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