ProcessKDP.cpp revision ea63601b1d4a21e46e477563f27d1b1c516136d8
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 32using namespace lldb; 33using namespace lldb_private; 34 35const char * 36ProcessKDP::GetPluginNameStatic() 37{ 38 return "kdp-remote"; 39} 40 41const char * 42ProcessKDP::GetPluginDescriptionStatic() 43{ 44 return "KDP Remote protocol based debugging plug-in for darwin kernel debugging."; 45} 46 47void 48ProcessKDP::Terminate() 49{ 50 PluginManager::UnregisterPlugin (ProcessKDP::CreateInstance); 51} 52 53 54lldb::ProcessSP 55ProcessKDP::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 65bool 66ProcessKDP::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//---------------------------------------------------------------------- 100ProcessKDP::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//---------------------------------------------------------------------- 113ProcessKDP::~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//---------------------------------------------------------------------- 126const char * 127ProcessKDP::GetPluginName() 128{ 129 return "Process debugging plug-in that uses the Darwin KDP remote protocol"; 130} 131 132const char * 133ProcessKDP::GetShortPluginName() 134{ 135 return GetPluginNameStatic(); 136} 137 138uint32_t 139ProcessKDP::GetPluginVersion() 140{ 141 return 1; 142} 143 144Error 145ProcessKDP::WillLaunch (Module* module) 146{ 147 Error error; 148 error.SetErrorString ("launching not supported in kdp-remote plug-in"); 149 return error; 150} 151 152Error 153ProcessKDP::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 160Error 161ProcessKDP::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 168Error 169ProcessKDP::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//---------------------------------------------------------------------- 253Error 254ProcessKDP::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 263Error 264ProcessKDP::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 271Error 272ProcessKDP::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 279Error 280ProcessKDP::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 288void 289ProcessKDP::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 300Error 301ProcessKDP::WillResume () 302{ 303 return Error(); 304} 305 306Error 307ProcessKDP::DoResume () 308{ 309 Error error; 310 if (m_comm.SendRequestResume ()) 311 { 312 SetPrivateState(eStateRunning); 313 DataExtractor exc_reply_packet; 314 if (m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 60 * USEC_PER_SEC)) 315 { 316 SetPrivateState(eStateStopped); 317 } 318 } 319 else 320 error.SetErrorString ("KDP resume failed"); 321 return error; 322} 323 324bool 325ProcessKDP::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list) 326{ 327 // locker will keep a mutex locked until it goes out of scope 328 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_THREAD)); 329 if (log && log->GetMask().Test(KDP_LOG_VERBOSE)) 330 log->Printf ("ProcessKDP::%s (pid = %llu)", __FUNCTION__, GetID()); 331 332 // We currently are making only one thread per core and we 333 // actually don't know about actual threads. Eventually we 334 // want to get the thread list from memory and note which 335 // threads are on CPU as those are the only ones that we 336 // will be able to resume. 337 const uint32_t cpu_mask = m_comm.GetCPUMask(); 338 for (uint32_t cpu_mask_bit = 1; cpu_mask_bit & cpu_mask; cpu_mask_bit <<= 1) 339 { 340 lldb::tid_t tid = cpu_mask_bit; 341 ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false)); 342 if (!thread_sp) 343 thread_sp.reset(new ThreadKDP (shared_from_this(), tid)); 344 new_thread_list.AddThread(thread_sp); 345 } 346 return new_thread_list.GetSize(false) > 0; 347} 348 349 350StateType 351ProcessKDP::SetThreadStopInfo (StringExtractor& stop_packet) 352{ 353 // TODO: figure out why we stopped given the packet that tells us we stopped... 354 return eStateStopped; 355} 356 357void 358ProcessKDP::RefreshStateAfterStop () 359{ 360 // Let all threads recover from stopping and do any clean up based 361 // on the previous thread state (if any). 362 m_thread_list.RefreshStateAfterStop(); 363 //SetThreadStopInfo (m_last_stop_packet); 364} 365 366Error 367ProcessKDP::DoHalt (bool &caused_stop) 368{ 369 Error error; 370 371// bool timed_out = false; 372 Mutex::Locker locker; 373 374 if (m_public_state.GetValue() == eStateAttaching) 375 { 376 // We are being asked to halt during an attach. We need to just close 377 // our file handle and debugserver will go away, and we can be done... 378 m_comm.Disconnect(); 379 } 380 else 381 { 382 if (!m_comm.SendRequestSuspend ()) 383 error.SetErrorString ("KDP halt failed"); 384 } 385 return error; 386} 387 388Error 389ProcessKDP::InterruptIfRunning (bool discard_thread_plans, 390 bool catch_stop_event, 391 EventSP &stop_event_sp) 392{ 393 Error error; 394 395 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 396 397 bool paused_private_state_thread = false; 398 const bool is_running = m_comm.IsRunning(); 399 if (log) 400 log->Printf ("ProcessKDP::InterruptIfRunning(discard_thread_plans=%i, catch_stop_event=%i) is_running=%i", 401 discard_thread_plans, 402 catch_stop_event, 403 is_running); 404 405 if (discard_thread_plans) 406 { 407 if (log) 408 log->Printf ("ProcessKDP::InterruptIfRunning() discarding all thread plans"); 409 m_thread_list.DiscardThreadPlans(); 410 } 411 if (is_running) 412 { 413 if (catch_stop_event) 414 { 415 if (log) 416 log->Printf ("ProcessKDP::InterruptIfRunning() pausing private state thread"); 417 PausePrivateStateThread(); 418 paused_private_state_thread = true; 419 } 420 421 bool timed_out = false; 422// bool sent_interrupt = false; 423 Mutex::Locker locker; 424 425 // TODO: implement halt in CommunicationKDP 426// if (!m_comm.SendInterrupt (locker, 1, sent_interrupt, timed_out)) 427// { 428// if (timed_out) 429// error.SetErrorString("timed out sending interrupt packet"); 430// else 431// error.SetErrorString("unknown error sending interrupt packet"); 432// if (paused_private_state_thread) 433// ResumePrivateStateThread(); 434// return error; 435// } 436 437 if (catch_stop_event) 438 { 439 // LISTEN HERE 440 TimeValue timeout_time; 441 timeout_time = TimeValue::Now(); 442 timeout_time.OffsetWithSeconds(5); 443 StateType state = WaitForStateChangedEventsPrivate (&timeout_time, stop_event_sp); 444 445 timed_out = state == eStateInvalid; 446 if (log) 447 log->Printf ("ProcessKDP::InterruptIfRunning() catch stop event: state = %s, timed-out=%i", StateAsCString(state), timed_out); 448 449 if (timed_out) 450 error.SetErrorString("unable to verify target stopped"); 451 } 452 453 if (paused_private_state_thread) 454 { 455 if (log) 456 log->Printf ("ProcessKDP::InterruptIfRunning() resuming private state thread"); 457 ResumePrivateStateThread(); 458 } 459 } 460 return error; 461} 462 463Error 464ProcessKDP::WillDetach () 465{ 466 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 467 if (log) 468 log->Printf ("ProcessKDP::WillDetach()"); 469 470 bool discard_thread_plans = true; 471 bool catch_stop_event = true; 472 EventSP event_sp; 473 return InterruptIfRunning (discard_thread_plans, catch_stop_event, event_sp); 474} 475 476Error 477ProcessKDP::DoDetach() 478{ 479 Error error; 480 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 481 if (log) 482 log->Printf ("ProcessKDP::DoDetach()"); 483 484 DisableAllBreakpointSites (); 485 486 m_thread_list.DiscardThreadPlans(); 487 488 if (m_comm.IsConnected()) 489 { 490 491 m_comm.SendRequestDisconnect(); 492 493 size_t response_size = m_comm.Disconnect (); 494 if (log) 495 { 496 if (response_size) 497 log->PutCString ("ProcessKDP::DoDetach() detach packet sent successfully"); 498 else 499 log->PutCString ("ProcessKDP::DoDetach() detach packet send failed"); 500 } 501 } 502 // Sleep for one second to let the process get all detached... 503 StopAsyncThread (); 504 505 m_comm.Clear(); 506 507 SetPrivateState (eStateDetached); 508 ResumePrivateStateThread(); 509 510 //KillDebugserverProcess (); 511 return error; 512} 513 514Error 515ProcessKDP::DoDestroy () 516{ 517 Error error; 518 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 519 if (log) 520 log->Printf ("ProcessKDP::DoDestroy()"); 521 522 // Interrupt if our inferior is running... 523 if (m_comm.IsConnected()) 524 { 525 if (m_public_state.GetValue() == eStateAttaching) 526 { 527 // We are being asked to halt during an attach. We need to just close 528 // our file handle and debugserver will go away, and we can be done... 529 m_comm.Disconnect(); 530 } 531 else 532 { 533 DisableAllBreakpointSites (); 534 535 m_comm.SendRequestDisconnect(); 536 537 StringExtractor response; 538 // TODO: Send kill packet? 539 SetExitStatus(SIGABRT, NULL); 540 } 541 } 542 StopAsyncThread (); 543 m_comm.Clear(); 544 return error; 545} 546 547//------------------------------------------------------------------ 548// Process Queries 549//------------------------------------------------------------------ 550 551bool 552ProcessKDP::IsAlive () 553{ 554 return m_comm.IsConnected() && m_private_state.GetValue() != eStateExited; 555} 556 557//------------------------------------------------------------------ 558// Process Memory 559//------------------------------------------------------------------ 560size_t 561ProcessKDP::DoReadMemory (addr_t addr, void *buf, size_t size, Error &error) 562{ 563 if (m_comm.IsConnected()) 564 return m_comm.SendRequestReadMemory (addr, buf, size, error); 565 error.SetErrorString ("not connected"); 566 return 0; 567} 568 569size_t 570ProcessKDP::DoWriteMemory (addr_t addr, const void *buf, size_t size, Error &error) 571{ 572 error.SetErrorString ("ProcessKDP::DoReadMemory not implemented"); 573 return 0; 574} 575 576lldb::addr_t 577ProcessKDP::DoAllocateMemory (size_t size, uint32_t permissions, Error &error) 578{ 579 error.SetErrorString ("memory allocation not suppported in kdp remote debugging"); 580 return LLDB_INVALID_ADDRESS; 581} 582 583Error 584ProcessKDP::DoDeallocateMemory (lldb::addr_t addr) 585{ 586 Error error; 587 error.SetErrorString ("memory deallocation not suppported in kdp remote debugging"); 588 return error; 589} 590 591Error 592ProcessKDP::EnableBreakpoint (BreakpointSite *bp_site) 593{ 594 if (m_comm.LocalBreakpointsAreSupported ()) 595 { 596 Error error; 597 if (!bp_site->IsEnabled()) 598 { 599 if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress())) 600 { 601 bp_site->SetEnabled(true); 602 bp_site->SetType (BreakpointSite::eExternal); 603 } 604 else 605 { 606 error.SetErrorString ("KDP set breakpoint failed"); 607 } 608 } 609 return error; 610 } 611 return EnableSoftwareBreakpoint (bp_site); 612} 613 614Error 615ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site) 616{ 617 if (m_comm.LocalBreakpointsAreSupported ()) 618 { 619 Error error; 620 if (bp_site->IsEnabled()) 621 { 622 BreakpointSite::Type bp_type = bp_site->GetType(); 623 if (bp_type == BreakpointSite::eExternal) 624 { 625 if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress())) 626 bp_site->SetEnabled(false); 627 else 628 error.SetErrorString ("KDP remove breakpoint failed"); 629 } 630 else 631 { 632 error = DisableSoftwareBreakpoint (bp_site); 633 } 634 } 635 return error; 636 } 637 return DisableSoftwareBreakpoint (bp_site); 638} 639 640Error 641ProcessKDP::EnableWatchpoint (Watchpoint *wp) 642{ 643 Error error; 644 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); 645 return error; 646} 647 648Error 649ProcessKDP::DisableWatchpoint (Watchpoint *wp) 650{ 651 Error error; 652 error.SetErrorString ("watchpoints are not suppported in kdp remote debugging"); 653 return error; 654} 655 656void 657ProcessKDP::Clear() 658{ 659 m_thread_list.Clear(); 660} 661 662Error 663ProcessKDP::DoSignal (int signo) 664{ 665 Error error; 666 error.SetErrorString ("sending signals is not suppported in kdp remote debugging"); 667 return error; 668} 669 670void 671ProcessKDP::Initialize() 672{ 673 static bool g_initialized = false; 674 675 if (g_initialized == false) 676 { 677 g_initialized = true; 678 PluginManager::RegisterPlugin (GetPluginNameStatic(), 679 GetPluginDescriptionStatic(), 680 CreateInstance); 681 682 Log::Callbacks log_callbacks = { 683 ProcessKDPLog::DisableLog, 684 ProcessKDPLog::EnableLog, 685 ProcessKDPLog::ListLogCategories 686 }; 687 688 Log::RegisterLogChannel (ProcessKDP::GetPluginNameStatic(), log_callbacks); 689 } 690} 691 692bool 693ProcessKDP::StartAsyncThread () 694{ 695 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 696 697 if (log) 698 log->Printf ("ProcessKDP::%s ()", __FUNCTION__); 699 700 // Create a thread that watches our internal state and controls which 701 // events make it to clients (into the DCProcess event queue). 702 m_async_thread = Host::ThreadCreate ("<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this, NULL); 703 return IS_VALID_LLDB_HOST_THREAD(m_async_thread); 704} 705 706void 707ProcessKDP::StopAsyncThread () 708{ 709 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet(KDP_LOG_PROCESS)); 710 711 if (log) 712 log->Printf ("ProcessKDP::%s ()", __FUNCTION__); 713 714 m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); 715 716 // Stop the stdio thread 717 if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) 718 { 719 Host::ThreadJoin (m_async_thread, NULL, NULL); 720 } 721} 722 723 724void * 725ProcessKDP::AsyncThread (void *arg) 726{ 727 ProcessKDP *process = (ProcessKDP*) arg; 728 729 LogSP log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PROCESS)); 730 if (log) 731 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread starting...", __FUNCTION__, arg, process->GetID()); 732 733 Listener listener ("ProcessKDP::AsyncThread"); 734 EventSP event_sp; 735 const uint32_t desired_event_mask = eBroadcastBitAsyncContinue | 736 eBroadcastBitAsyncThreadShouldExit; 737 738 if (listener.StartListeningForEvents (&process->m_async_broadcaster, desired_event_mask) == desired_event_mask) 739 { 740 listener.StartListeningForEvents (&process->m_comm, Communication::eBroadcastBitReadThreadDidExit); 741 742 bool done = false; 743 while (!done) 744 { 745 if (log) 746 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID()); 747 if (listener.WaitForEvent (NULL, event_sp)) 748 { 749 const uint32_t event_type = event_sp->GetType(); 750 if (event_sp->BroadcasterIs (&process->m_async_broadcaster)) 751 { 752 if (log) 753 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) Got an event of type: %d...", __FUNCTION__, arg, process->GetID(), event_type); 754 755 switch (event_type) 756 { 757 case eBroadcastBitAsyncContinue: 758 { 759 const EventDataBytes *continue_packet = EventDataBytes::GetEventDataFromEvent(event_sp.get()); 760 761 if (continue_packet) 762 { 763 // TODO: do continue support here 764 765// const char *continue_cstr = (const char *)continue_packet->GetBytes (); 766// const size_t continue_cstr_len = continue_packet->GetByteSize (); 767// if (log) 768// log->Printf ("ProcessKDP::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr); 769// 770// if (::strstr (continue_cstr, "vAttach") == NULL) 771// process->SetPrivateState(eStateRunning); 772// StringExtractor response; 773// StateType stop_state = process->GetCommunication().SendContinuePacketAndWaitForResponse (process, continue_cstr, continue_cstr_len, response); 774// 775// switch (stop_state) 776// { 777// case eStateStopped: 778// case eStateCrashed: 779// case eStateSuspended: 780// process->m_last_stop_packet = response; 781// process->SetPrivateState (stop_state); 782// break; 783// 784// case eStateExited: 785// process->m_last_stop_packet = response; 786// response.SetFilePos(1); 787// process->SetExitStatus(response.GetHexU8(), NULL); 788// done = true; 789// break; 790// 791// case eStateInvalid: 792// process->SetExitStatus(-1, "lost connection"); 793// break; 794// 795// default: 796// process->SetPrivateState (stop_state); 797// break; 798// } 799 } 800 } 801 break; 802 803 case eBroadcastBitAsyncThreadShouldExit: 804 if (log) 805 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID()); 806 done = true; 807 break; 808 809 default: 810 if (log) 811 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type); 812 done = true; 813 break; 814 } 815 } 816 else if (event_sp->BroadcasterIs (&process->m_comm)) 817 { 818 if (event_type & Communication::eBroadcastBitReadThreadDidExit) 819 { 820 process->SetExitStatus (-1, "lost connection"); 821 done = true; 822 } 823 } 824 } 825 else 826 { 827 if (log) 828 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID()); 829 done = true; 830 } 831 } 832 } 833 834 if (log) 835 log->Printf ("ProcessKDP::%s (arg = %p, pid = %llu) thread exiting...", __FUNCTION__, arg, process->GetID()); 836 837 process->m_async_thread = LLDB_INVALID_HOST_THREAD; 838 return NULL; 839} 840 841 842