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.Clear(); 473 474 SetPrivateState (eStateDetached); 475 ResumePrivateStateThread(); 476 477 //KillDebugserverProcess (); 478 return error; 479 } 480 481 Error 482 ProcessKDP::DoDestroy () 483 { 484 Error error; 485 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 486 if (log) 487 log->Printf ("ProcessKDP::DoDestroy()"); 488 489 // Interrupt if our inferior is running... 490 if (m_comm.IsConnected()) 491 { 492 if (m_public_state.GetValue() == eStateAttaching) 493 { 494 // We are being asked to halt during an attach. We need to just close 495 // our file handle and debugserver will go away, and we can be done... 496 m_comm.Disconnect(); 497 } 498 else 499 { 500 DisableAllBreakpointSites (); 501 502 m_comm.SendRequestDisconnect(); 503 504 StringExtractor response; 505 // TODO: Send kill packet? 506 SetExitStatus(SIGABRT, NULL); 507 } 508 } 509 StopAsyncThread (); 510 m_comm.Clear(); 511 return error; 512 } 513 514 //------------------------------------------------------------------ 515 // Process Queries 516 //------------------------------------------------------------------ 517 518 bool 519 ProcessKDP::IsAlive () 520 { 521 return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited; 522 } 523 524 //------------------------------------------------------------------ 525 // Process Memory 526 //------------------------------------------------------------------ 527 size_t 528 ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error) 529 { 530 if (m_comm.IsConnected()) 531 return m_comm.SendRequestReadMemory (addr, buf, size, error); 532 error.SetErrorString ("not connected"); 533 return 0; 534 } 535 536 size_t 537 ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error) 538 { 539 error.SetErrorString ("ProcessKDP::DoReadMemory not implemented"); 540 return 0; 541 } 542 543 lldb::addr_t 544 ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error) 545 { 546 error.SetErrorString ("memory allocation not suppported in kdp remote debugging"); 547 return LLDB_INVALID_ADDRESS; 548 } 549 550 Error 551 ProcessKDP::DoDeallocateMemory (lldb::addr_t addr) 552 { 553 Error error; 554 error.SetErrorString ("memory deallocation not suppported in kdp remote debugging"); 555 return error; 556 } 557 558 Error 559 ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site) 560 { 561 if (m_comm.LocalBreakpointsAreSupported ()) 562 { 563 Error error; 564 if (!bp_site->IsEnabled()) 565 { 566 if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress())) 567 { 568 bp_site->SetEnabled(true); 569 bp_site->SetType (BreakpointSite::eExternal); 570 } 571 else 572 { 573 error.SetErrorString ("KDP set breakpoint failed"); 574 } 575 } 576 return error; 577 } 578 return EnableSoftwareBreakpoint (bp_site); 579 } 580 581 Error 582 ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site) 583 { 584 if (m_comm.LocalBreakpointsAreSupported ()) 585 { 586 Error error; 587 if (bp_site->IsEnabled()) 588 { 589 BreakpointSite::Type bp_type = bp_site->GetType(); 590 if (bp_type == BreakpointSite::eExternal) 591 { 592 if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress())) 593 bp_site->SetEnabled(false); 594 else 595 error.SetErrorString ("KDP remove breakpoint failed"); 596 } 597 else 598 { 599 error = DisableSoftwareBreakpoint (bp_site); 600 } 601 } 602 return error; 603 } 604 return DisableSoftwareBreakpoint (bp_site); 605 } 606 607 Error 608 ProcessKDP::EnableWatchpoint (Watchpoint *wp) 609 { 610 Error error; 611 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); 612 return error; 613 } 614 615 Error 616 ProcessKDP::DisableWatchpoint (Watchpoint *wp) 617 { 618 Error error; 619 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); 620 return error; 621 } 622 623 void 624 ProcessKDP::Clear() 625 { 626 m_thread_list.Clear(); 627 } 628 629 Error 630 ProcessKDP::DoSignal (int signo) 631 { 632 Error error; 633 error.SetErrorString ("sending signals is not suppported in kdp remote debugging"); 634 return error; 635 } 636 637 void 638 ProcessKDP::Initialize() 639 { 640 static bool g_initialized = false; 641 642 if (g_initialized == false) 643 { 644 g_initialized = true; 645 PluginManager::RegisterPlugin (GetPluginNameStatic(), 646 GetPluginDescriptionStatic(), 647 CreateInstance); 648 649 Log::Callbacks log_callbacks = { 650 ProcessKDPLog::DisableLog, 651 ProcessKDPLog::EnableLog, 652 ProcessKDPLog::ListLogCategories 653 }; 654 655 Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks); 656 } 657 } 658 659 bool 660 ProcessKDP::StartAsyncThread () 661 { 662 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 663 664 if (log) 665 log->Printf ("ProcessKDP::%s ()", __FUNCTION__); 666 667 // Create a thread that watches our internal state and controls which 668 // events make it to clients (into the DCProcess event queue). 669 m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL); 670 return IS_VALID_LLDB_HOST_THREAD(m_async_thread); 671 } 672 673 void 674 ProcessKDP::StopAsyncThread () 675 { 676 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 677 678 if (log) 679 log->Printf ("ProcessKDP::%s ()", __FUNCTION__); 680 681 m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); 682 683 // Stop the stdio thread 684 if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) 685 { 686 Host::ThreadJoin (m_async_thread, NULL, NULL); 687 } 688 } 689 690 691 void * 692 ProcessKDP::AsyncThread (void *arg) 693 { 694 ProcessKDP *process = (ProcessKDP*) arg; 695 696 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS)); 697 if (log) 698 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread starting...", __FUNCTION__, arg, process->GetID()); 699 700 Listener listener ("ProcessKDP::AsyncThread"); 701 EventSP event_sp; 702 const uint32_t desired_event_mask = eBroadcastBitAsyncContinue | 703 eBroadcastBitAsyncThreadShouldExit; 704 705 if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask) 706 { 707 listener.StartListeningForEvents (&process->m_comm, Communication::eBroadcastBitReadThreadDidExit); 708 709 bool done = false; 710 while (!done) 711 { 712 if (log) 713 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID()); 714 if (listener.WaitForEvent (NULL, event_sp)) 715 { 716 const uint32_t event_type = event_sp->GetType(); 717 if (event_sp->BroadcasterIs (&process->m_async_broadcaster)) 718 { 719 if (log) 720 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type); 721 722 switch (event_type) 723 { 724 case eBroadcastBitAsyncContinue: 725 { 726 const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get()); 727 728 if (continue_packet) 729 { 730 // TODO: do continue support here 731 732 // const char *continue_cstr = (const char *)continue_packet->GetBytes (); 733 // const size_t continue_cstr_len = continue_packet->GetByteSize (); 734 // if (log) 735 // log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr); 736 // 737 // if (::strstr (continue_cstr, "vAttach") == NULL) 738 // process->SetPrivateState(eStateRunning); 739 // StringExtractor response; 740 // StateType stop_state = process->GetCommunication().SendContinuePacketAndWaitForResponse (process, continue_cstr, continue_cstr_len, response); 741 // 742 // switch (stop_state) 743 // { 744 // case eStateStopped: 745 // case eStateCrashed: 746 // case eStateSuspended: 747 // process->m_last_stop_packet = response; 748 // process->SetPrivateState (stop_state); 749 // break; 750 // 751 // case eStateExited: 752 // process->m_last_stop_packet = response; 753 // response.SetFilePos(1); 754 // process->SetExitStatus(response.GetHexU8(), NULL); 755 // done = true; 756 // break; 757 // 758 // case eStateInvalid: 759 // process->SetExitStatus(-1, "lost connection"); 760 // break; 761 // 762 // default: 763 // process->SetPrivateState (stop_state); 764 // break; 765 // } 766 } 767 } 768 break; 769 770 case eBroadcastBitAsyncThreadShouldExit: 771 if (log) 772 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID()); 773 done = true; 774 break; 775 776 default: 777 if (log) 778 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); 779 done = true; 780 break; 781 } 782 } 783 else if (event_sp->BroadcasterIs (&process->m_comm)) 784 { 785 if (event_type & Communication::eBroadcastBitReadThreadDidExit) 786 { 787 process->SetExitStatus (-1, "lost connection"); 788 done = true; 789 } 790 } 791 } 792 else 793 { 794 if (log) 795 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID()); 796 done = true; 797 } 798 } 799 } 800 801 if (log) 802 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread exiting...", __FUNCTION__, arg, process->GetID()); 803 804 process->m_async_thread = LLDB_INVALID_HOST_THREAD; 805 return NULL; 806 } 807 808 809