blob: 6d33ea286348cad09adddcbc7100362f3c87d0ad [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 Clayton363be3f2011-07-15 03:27:12 +000017#include "lldb/Core/PluginManager.h"
18#include "lldb/Core/State.h"
19#include "lldb/Host/Host.h"
Greg Clayton1e5b0212011-07-15 16:31:38 +000020#include "lldb/Target/Target.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000021#include "lldb/Target/Thread.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000022
23// Project includes
24#include "ProcessKDP.h"
25#include "ProcessKDPLog.h"
Greg Clayton0fa51242011-07-19 03:57:15 +000026#include "ThreadKDP.h"
Greg Clayton363be3f2011-07-15 03:27:12 +000027#include "StopInfoMachException.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
32const char *
33ProcessKDP::GetPluginNameStatic()
34{
35 return "kdp-remote";
36}
37
38const char *
39ProcessKDP::GetPluginDescriptionStatic()
40{
41 return "KDP Remote protocol based debugging plug-in for darwin kernel debugging.";
42}
43
44void
45ProcessKDP::Terminate()
46{
47 PluginManager::UnregisterPlugin (ProcessKDP::CreateInstance);
48}
49
50
51Process*
52ProcessKDP::CreateInstance (Target &target, Listener &listener)
53{
54 return new ProcessKDP (target, listener);
55}
56
57bool
Greg Clayton8d2ea282011-07-17 20:36:25 +000058ProcessKDP::CanDebug(Target &target, bool plugin_specified_by_name)
Greg Clayton363be3f2011-07-15 03:27:12 +000059{
60 // For now we are just making sure the file exists for a given module
61 ModuleSP exe_module_sp(target.GetExecutableModule());
62 if (exe_module_sp.get())
63 {
64 const llvm::Triple &triple_ref = target.GetArchitecture().GetTriple();
65 if (triple_ref.getOS() == llvm::Triple::Darwin &&
66 triple_ref.getVendor() == llvm::Triple::Apple)
67 {
Greg Clayton363be3f2011-07-15 03:27:12 +000068 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
69 if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
70 exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
71 return true;
72 }
Greg Clayton8d2ea282011-07-17 20:36:25 +000073 return false;
Greg Clayton363be3f2011-07-15 03:27:12 +000074 }
Greg Clayton8d2ea282011-07-17 20:36:25 +000075 // No target executable, assume we can debug if our plug-in was specified by name
76 return plugin_specified_by_name;
Greg Clayton363be3f2011-07-15 03:27:12 +000077}
78
79//----------------------------------------------------------------------
80// ProcessKDP constructor
81//----------------------------------------------------------------------
82ProcessKDP::ProcessKDP(Target& target, Listener &listener) :
83 Process (target, listener),
84 m_comm("lldb.process.kdp-remote.communication"),
85 m_async_broadcaster ("lldb.process.kdp-remote.async-broadcaster"),
86 m_async_thread (LLDB_INVALID_HOST_THREAD)
87{
88// m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit");
89// m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue");
90}
91
92//----------------------------------------------------------------------
93// Destructor
94//----------------------------------------------------------------------
95ProcessKDP::~ProcessKDP()
96{
97 Clear();
98}
99
100//----------------------------------------------------------------------
101// PluginInterface
102//----------------------------------------------------------------------
103const char *
104ProcessKDP::GetPluginName()
105{
106 return "Process debugging plug-in that uses the Darwin KDP remote protocol";
107}
108
109const char *
110ProcessKDP::GetShortPluginName()
111{
112 return GetPluginNameStatic();
113}
114
115uint32_t
116ProcessKDP::GetPluginVersion()
117{
118 return 1;
119}
120
121Error
122ProcessKDP::WillLaunch (Module* module)
123{
124 Error error;
125 error.SetErrorString ("launching not supported in kdp-remote plug-in");
126 return error;
127}
128
129Error
130ProcessKDP::WillAttachToProcessWithID (lldb::pid_t pid)
131{
132 Error error;
133 error.SetErrorString ("attaching to a by process ID not supported in kdp-remote plug-in");
134 return error;
135}
136
137Error
138ProcessKDP::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
139{
140 Error error;
141 error.SetErrorString ("attaching to a by process name not supported in kdp-remote plug-in");
142 return error;
143}
144
145Error
146ProcessKDP::DoConnectRemote (const char *remote_url)
147{
148 // TODO: fill in the remote connection to the remote KDP here!
149 Error error;
Greg Clayton8d2ea282011-07-17 20:36:25 +0000150
151 if (remote_url == NULL || remote_url[0] == '\0')
152 remote_url = "udp://localhost:41139";
153
154 std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
155 if (conn_ap.get())
156 {
157 // Only try once for now.
158 // TODO: check if we should be retrying?
159 const uint32_t max_retry_count = 1;
160 for (uint32_t retry_count = 0; retry_count < max_retry_count; ++retry_count)
161 {
162 if (conn_ap->Connect(remote_url, &error) == eConnectionStatusSuccess)
163 break;
164 usleep (100000);
165 }
166 }
167
168 if (conn_ap->IsConnected())
169 {
170 const uint16_t reply_port = conn_ap->GetReadPort ();
171
172 if (reply_port != 0)
173 {
174 m_comm.SetConnection(conn_ap.release());
175
176 if (m_comm.SendRequestReattach(reply_port))
177 {
178 if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB..."))
179 {
180 m_comm.GetVersion();
181 uint32_t cpu = m_comm.GetCPUType();
182 uint32_t sub = m_comm.GetCPUSubtype();
183 ArchSpec kernel_arch;
184 kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
185 m_target.SetArchitecture(kernel_arch);
Greg Clayton0fa51242011-07-19 03:57:15 +0000186
187 SetID (1);
188 UpdateThreadListIfNeeded ();
189 SetPrivateState (eStateStopped);
Greg Clayton8d2ea282011-07-17 20:36:25 +0000190 }
191 }
192 else
193 {
194 error.SetErrorString("KDP reattach failed");
195 }
196 }
197 else
198 {
199 error.SetErrorString("invalid reply port from UDP connection");
200 }
201 }
202 else
203 {
204 if (error.Success())
205 error.SetErrorStringWithFormat ("failed to connect to '%s'", remote_url);
206 }
207 if (error.Fail())
208 m_comm.Disconnect();
209
Greg Clayton363be3f2011-07-15 03:27:12 +0000210 return error;
211}
212
213//----------------------------------------------------------------------
214// Process Control
215//----------------------------------------------------------------------
216Error
217ProcessKDP::DoLaunch (Module* module,
218 char const *argv[],
219 char const *envp[],
220 uint32_t launch_flags,
221 const char *stdin_path,
222 const char *stdout_path,
223 const char *stderr_path,
224 const char *working_dir)
225{
226 Error error;
227 error.SetErrorString ("launching not supported in kdp-remote plug-in");
228 return error;
229}
230
231
232Error
233ProcessKDP::DoAttachToProcessWithID (lldb::pid_t attach_pid)
234{
235 Error error;
236 error.SetErrorString ("attach to process by ID is not suppported in kdp remote debugging");
237 return error;
238}
239
240size_t
241ProcessKDP::AttachInputReaderCallback (void *baton,
242 InputReader *reader,
243 lldb::InputReaderAction notification,
244 const char *bytes,
245 size_t bytes_len)
246{
247 if (notification == eInputReaderGotToken)
248 {
249// ProcessKDP *process = (ProcessKDP *)baton;
250// if (process->m_waiting_for_attach)
251// process->m_waiting_for_attach = false;
252 reader->SetIsDone(true);
253 return 1;
254 }
255 return 0;
256}
257
258Error
259ProcessKDP::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
260{
261 Error error;
262 error.SetErrorString ("attach to process by name is not suppported in kdp remote debugging");
263 return error;
264}
265
266
267void
268ProcessKDP::DidAttach ()
269{
270 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS));
271 if (log)
272 log->Printf ("ProcessKDP::DidLaunch()");
273 if (GetID() != LLDB_INVALID_PROCESS_ID)
274 {
275 // TODO: figure out the register context that we will use
276 }
277}
278
279Error
280ProcessKDP::WillResume ()
281{
282 return Error();
283}
284
285Error
286ProcessKDP::DoResume ()
287{
288 Error error;
289 error.SetErrorString ("ProcessKDP::DoResume () is not implemented yet");
290 return error;
291}
292
293uint32_t
294ProcessKDP::UpdateThreadListIfNeeded ()
295{
296 // locker will keep a mutex locked until it goes out of scope
297 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD));
298 if (log && log->GetMask().Test(KDP_LOG_VERBOSE))
299 log->Printf ("ProcessKDP::%s (pid = %i)", __FUNCTION__, GetID());
300
301 Mutex::Locker locker (m_thread_list.GetMutex ());
Greg Clayton363be3f2011-07-15 03:27:12 +0000302 const uint32_t stop_id = GetStopID();
Greg Clayton0fa51242011-07-19 03:57:15 +0000303 if (m_thread_list.GetSize(false) == 0)
Greg Clayton363be3f2011-07-15 03:27:12 +0000304 {
Greg Clayton0fa51242011-07-19 03:57:15 +0000305 // We currently are making only one thread per core and we
306 // actually don't know about actual threads. Eventually we
307 // want to get the thread list from memory and note which
308 // threads are on CPU as those are the only ones that we
309 // will be able to resume.
310 ThreadList curr_thread_list (this);
311 curr_thread_list.SetStopID(stop_id);
312 const uint32_t cpu_mask = m_comm.GetCPUMask();
313 for (uint32_t cpu_mask_bit = 1; cpu_mask_bit & cpu_mask; cpu_mask_bit <<= 1)
314 {
315 // The thread ID is currently the CPU mask bit
316 ThreadSP thread_sp (new ThreadKDP (*this, cpu_mask_bit));
317 curr_thread_list.AddThread(thread_sp);
318 }
319 m_thread_list = curr_thread_list;
Greg Clayton363be3f2011-07-15 03:27:12 +0000320 }
321 return GetThreadList().GetSize(false);
322}
323
324
325StateType
326ProcessKDP::SetThreadStopInfo (StringExtractor& stop_packet)
327{
328 // TODO: figure out why we stopped given the packet that tells us we stopped...
329 return eStateStopped;
330}
331
332void
333ProcessKDP::RefreshStateAfterStop ()
334{
335 // Let all threads recover from stopping and do any clean up based
336 // on the previous thread state (if any).
337 m_thread_list.RefreshStateAfterStop();
338 //SetThreadStopInfo (m_last_stop_packet);
339}
340
341Error
342ProcessKDP::DoHalt (bool &caused_stop)
343{
344 Error error;
345
346// bool timed_out = false;
347 Mutex::Locker locker;
348
349 if (m_public_state.GetValue() == eStateAttaching)
350 {
351 // We are being asked to halt during an attach. We need to just close
352 // our file handle and debugserver will go away, and we can be done...
353 m_comm.Disconnect();
354 }
355 else
356 {
357 // TODO: add the ability to halt a running kernel
358 error.SetErrorString ("halt not supported in kdp-remote plug-in");
359// if (!m_comm.SendInterrupt (locker, 2, caused_stop, timed_out))
360// {
361// if (timed_out)
362// error.SetErrorString("timed out sending interrupt packet");
363// else
364// error.SetErrorString("unknown error sending interrupt packet");
365// }
366 }
367 return error;
368}
369
370Error
371ProcessKDP::InterruptIfRunning (bool discard_thread_plans,
372 bool catch_stop_event,
373 EventSP &stop_event_sp)
374{
375 Error error;
376
377 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
378
379 bool paused_private_state_thread = false;
380 const bool is_running = m_comm.IsRunning();
381 if (log)
382 log->Printf ("ProcessKDP::InterruptIfRunning(discard_thread_plans=%i, catch_stop_event=%i) is_running=%i",
383 discard_thread_plans,
384 catch_stop_event,
385 is_running);
386
387 if (discard_thread_plans)
388 {
389 if (log)
390 log->Printf ("ProcessKDP::InterruptIfRunning() discarding all thread plans");
391 m_thread_list.DiscardThreadPlans();
392 }
393 if (is_running)
394 {
395 if (catch_stop_event)
396 {
397 if (log)
398 log->Printf ("ProcessKDP::InterruptIfRunning() pausing private state thread");
399 PausePrivateStateThread();
400 paused_private_state_thread = true;
401 }
402
403 bool timed_out = false;
404// bool sent_interrupt = false;
405 Mutex::Locker locker;
406
407 // TODO: implement halt in CommunicationKDP
408// if (!m_comm.SendInterrupt (locker, 1, sent_interrupt, timed_out))
409// {
410// if (timed_out)
411// error.SetErrorString("timed out sending interrupt packet");
412// else
413// error.SetErrorString("unknown error sending interrupt packet");
414// if (paused_private_state_thread)
415// ResumePrivateStateThread();
416// return error;
417// }
418
419 if (catch_stop_event)
420 {
421 // LISTEN HERE
422 TimeValue timeout_time;
423 timeout_time = TimeValue::Now();
424 timeout_time.OffsetWithSeconds(5);
425 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, stop_event_sp);
426
427 timed_out = state == eStateInvalid;
428 if (log)
429 log->Printf ("ProcessKDP::InterruptIfRunning() catch stop event: state = %s, timed-out=%i", StateAsCString(state), timed_out);
430
431 if (timed_out)
432 error.SetErrorString("unable to verify target stopped");
433 }
434
435 if (paused_private_state_thread)
436 {
437 if (log)
438 log->Printf ("ProcessKDP::InterruptIfRunning() resuming private state thread");
439 ResumePrivateStateThread();
440 }
441 }
442 return error;
443}
444
445Error
446ProcessKDP::WillDetach ()
447{
448 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
449 if (log)
450 log->Printf ("ProcessKDP::WillDetach()");
451
452 bool discard_thread_plans = true;
453 bool catch_stop_event = true;
454 EventSP event_sp;
455 return InterruptIfRunning (discard_thread_plans, catch_stop_event, event_sp);
456}
457
458Error
459ProcessKDP::DoDetach()
460{
461 Error error;
462 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
463 if (log)
464 log->Printf ("ProcessKDP::DoDetach()");
465
466 DisableAllBreakpointSites ();
467
468 m_thread_list.DiscardThreadPlans();
469
Greg Clayton8d2ea282011-07-17 20:36:25 +0000470 if (m_comm.IsConnected())
Greg Clayton363be3f2011-07-15 03:27:12 +0000471 {
Greg Clayton8d2ea282011-07-17 20:36:25 +0000472
473 m_comm.SendRequestDisconnect();
474
475 size_t response_size = m_comm.Disconnect ();
476 if (log)
477 {
478 if (response_size)
479 log->PutCString ("ProcessKDP::DoDetach() detach packet sent successfully");
480 else
481 log->PutCString ("ProcessKDP::DoDetach() detach packet send failed");
482 }
Greg Clayton363be3f2011-07-15 03:27:12 +0000483 }
484 // Sleep for one second to let the process get all detached...
485 StopAsyncThread ();
486
487 m_comm.StopReadThread();
488 m_comm.Disconnect(); // Disconnect from the debug server.
489
490 SetPrivateState (eStateDetached);
491 ResumePrivateStateThread();
492
493 //KillDebugserverProcess ();
494 return error;
495}
496
497Error
498ProcessKDP::DoDestroy ()
499{
500 Error error;
501 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS));
502 if (log)
503 log->Printf ("ProcessKDP::DoDestroy()");
504
505 // Interrupt if our inferior is running...
506 if (m_comm.IsConnected())
507 {
Greg Clayton8d2ea282011-07-17 20:36:25 +0000508 m_comm.SendRequestDisconnect();
509
Greg Clayton363be3f2011-07-15 03:27:12 +0000510 if (m_public_state.GetValue() == eStateAttaching)
511 {
512 // We are being asked to halt during an attach. We need to just close
513 // our file handle and debugserver will go away, and we can be done...
514 m_comm.Disconnect();
515 }
516 else
517 {
518
519 StringExtractor response;
520 // TODO: Send kill packet?
521 SetExitStatus(SIGABRT, NULL);
522 }
523 }
524 StopAsyncThread ();
525 m_comm.StopReadThread();
526 m_comm.Disconnect(); // Disconnect from the debug server.
527 return error;
528}
529
530//------------------------------------------------------------------
531// Process Queries
532//------------------------------------------------------------------
533
534bool
535ProcessKDP::IsAlive ()
536{
537 return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
538}
539
540//------------------------------------------------------------------
541// Process Memory
542//------------------------------------------------------------------
543size_t
544ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error)
545{
Greg Clayton0fa51242011-07-19 03:57:15 +0000546 if (m_comm.IsConnected())
547 return m_comm.SendRequestReadMemory (addr, buf, size, error);
548 error.SetErrorString ("not connected");
Greg Clayton363be3f2011-07-15 03:27:12 +0000549 return 0;
550}
551
552size_t
553ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
554{
555 error.SetErrorString ("ProcessKDP::DoReadMemory not implemented");
556 return 0;
557}
558
559lldb::addr_t
560ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error)
561{
562 error.SetErrorString ("memory allocation not suppported in kdp remote debugging");
563 return LLDB_INVALID_ADDRESS;
564}
565
566Error
567ProcessKDP::DoDeallocateMemory (lldb::addr_t addr)
568{
569 Error error;
570 error.SetErrorString ("memory deallocation not suppported in kdp remote debugging");
571 return error;
572}
573
574Error
575ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site)
576{
577 return EnableSoftwareBreakpoint (bp_site);
578}
579
580Error
581ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site)
582{
583 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