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