1 //===-- SBProcess.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 #include "lldb/API/SBProcess.h" 11 12 // C Includes 13 #include <inttypes.h> 14 15 #include "lldb/lldb-defines.h" 16 #include "lldb/lldb-types.h" 17 18 #include "lldb/Interpreter/Args.h" 19 #include "lldb/Core/Debugger.h" 20 #include "lldb/Core/Log.h" 21 #include "lldb/Core/Module.h" 22 #include "lldb/Core/State.h" 23 #include "lldb/Core/Stream.h" 24 #include "lldb/Core/StreamFile.h" 25 #include "lldb/Target/Process.h" 26 #include "lldb/Target/RegisterContext.h" 27 #include "lldb/Target/SystemRuntime.h" 28 #include "lldb/Target/Target.h" 29 #include "lldb/Target/Thread.h" 30 31 // Project includes 32 33 #include "lldb/API/SBBroadcaster.h" 34 #include "lldb/API/SBCommandReturnObject.h" 35 #include "lldb/API/SBDebugger.h" 36 #include "lldb/API/SBEvent.h" 37 #include "lldb/API/SBFileSpec.h" 38 #include "lldb/API/SBThread.h" 39 #include "lldb/API/SBThreadCollection.h" 40 #include "lldb/API/SBStream.h" 41 #include "lldb/API/SBStringList.h" 42 #include "lldb/API/SBUnixSignals.h" 43 44 using namespace lldb; 45 using namespace lldb_private; 46 47 48 SBProcess::SBProcess () : 49 m_opaque_wp() 50 { 51 } 52 53 54 //---------------------------------------------------------------------- 55 // SBProcess constructor 56 //---------------------------------------------------------------------- 57 58 SBProcess::SBProcess (const SBProcess& rhs) : 59 m_opaque_wp (rhs.m_opaque_wp) 60 { 61 } 62 63 64 SBProcess::SBProcess (const lldb::ProcessSP &process_sp) : 65 m_opaque_wp (process_sp) 66 { 67 } 68 69 const SBProcess& 70 SBProcess::operator = (const SBProcess& rhs) 71 { 72 if (this != &rhs) 73 m_opaque_wp = rhs.m_opaque_wp; 74 return *this; 75 } 76 77 //---------------------------------------------------------------------- 78 // Destructor 79 //---------------------------------------------------------------------- 80 SBProcess::~SBProcess() 81 { 82 } 83 84 const char * 85 SBProcess::GetBroadcasterClassName () 86 { 87 return Process::GetStaticBroadcasterClass().AsCString(); 88 } 89 90 const char * 91 SBProcess::GetPluginName () 92 { 93 ProcessSP process_sp(GetSP()); 94 if (process_sp) 95 { 96 return process_sp->GetPluginName().GetCString(); 97 } 98 return "<Unknown>"; 99 } 100 101 const char * 102 SBProcess::GetShortPluginName () 103 { 104 ProcessSP process_sp(GetSP()); 105 if (process_sp) 106 { 107 return process_sp->GetPluginName().GetCString(); 108 } 109 return "<Unknown>"; 110 } 111 112 113 lldb::ProcessSP 114 SBProcess::GetSP() const 115 { 116 return m_opaque_wp.lock(); 117 } 118 119 void 120 SBProcess::SetSP (const ProcessSP &process_sp) 121 { 122 m_opaque_wp = process_sp; 123 } 124 125 void 126 SBProcess::Clear () 127 { 128 m_opaque_wp.reset(); 129 } 130 131 132 bool 133 SBProcess::IsValid() const 134 { 135 ProcessSP process_sp(m_opaque_wp.lock()); 136 return ((bool) process_sp && process_sp->IsValid()); 137 } 138 139 bool 140 SBProcess::RemoteLaunch (char const **argv, 141 char const **envp, 142 const char *stdin_path, 143 const char *stdout_path, 144 const char *stderr_path, 145 const char *working_directory, 146 uint32_t launch_flags, 147 bool stop_at_entry, 148 lldb::SBError& error) 149 { 150 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 151 if (log) 152 log->Printf ("SBProcess(%p)::RemoteLaunch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", 153 static_cast<void*>(m_opaque_wp.lock().get()), 154 static_cast<void*>(argv), static_cast<void*>(envp), 155 stdin_path ? stdin_path : "NULL", 156 stdout_path ? stdout_path : "NULL", 157 stderr_path ? stderr_path : "NULL", 158 working_directory ? working_directory : "NULL", 159 launch_flags, stop_at_entry, 160 static_cast<void*>(error.get())); 161 162 ProcessSP process_sp(GetSP()); 163 if (process_sp) 164 { 165 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 166 if (process_sp->GetState() == eStateConnected) 167 { 168 if (stop_at_entry) 169 launch_flags |= eLaunchFlagStopAtEntry; 170 ProcessLaunchInfo launch_info(FileSpec{stdin_path, false}, 171 FileSpec{stdout_path, false}, 172 FileSpec{stderr_path, false}, 173 FileSpec{working_directory, false}, 174 launch_flags); 175 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 176 if (exe_module) 177 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 178 if (argv) 179 launch_info.GetArguments().AppendArguments (argv); 180 if (envp) 181 launch_info.GetEnvironmentEntries ().SetArguments (envp); 182 error.SetError (process_sp->Launch (launch_info)); 183 } 184 else 185 { 186 error.SetErrorString ("must be in eStateConnected to call RemoteLaunch"); 187 } 188 } 189 else 190 { 191 error.SetErrorString ("unable to attach pid"); 192 } 193 194 if (log) { 195 SBStream sstr; 196 error.GetDescription (sstr); 197 log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", 198 static_cast<void*>(process_sp.get()), 199 static_cast<void*>(error.get()), sstr.GetData()); 200 } 201 202 return error.Success(); 203 } 204 205 bool 206 SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) 207 { 208 ProcessSP process_sp(GetSP()); 209 if (process_sp) 210 { 211 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 212 if (process_sp->GetState() == eStateConnected) 213 { 214 ProcessAttachInfo attach_info; 215 attach_info.SetProcessID (pid); 216 error.SetError (process_sp->Attach (attach_info)); 217 } 218 else 219 { 220 error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID"); 221 } 222 } 223 else 224 { 225 error.SetErrorString ("unable to attach pid"); 226 } 227 228 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 229 if (log) { 230 SBStream sstr; 231 error.GetDescription (sstr); 232 log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s", 233 static_cast<void*>(process_sp.get()), pid, 234 static_cast<void*>(error.get()), sstr.GetData()); 235 } 236 237 return error.Success(); 238 } 239 240 241 uint32_t 242 SBProcess::GetNumThreads () 243 { 244 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 245 246 uint32_t num_threads = 0; 247 ProcessSP process_sp(GetSP()); 248 if (process_sp) 249 { 250 Process::StopLocker stop_locker; 251 252 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 253 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 254 num_threads = process_sp->GetThreadList().GetSize(can_update); 255 } 256 257 if (log) 258 log->Printf ("SBProcess(%p)::GetNumThreads () => %d", 259 static_cast<void*>(process_sp.get()), num_threads); 260 261 return num_threads; 262 } 263 264 SBThread 265 SBProcess::GetSelectedThread () const 266 { 267 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 268 269 SBThread sb_thread; 270 ThreadSP thread_sp; 271 ProcessSP process_sp(GetSP()); 272 if (process_sp) 273 { 274 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 275 thread_sp = process_sp->GetThreadList().GetSelectedThread(); 276 sb_thread.SetThread (thread_sp); 277 } 278 279 if (log) 280 log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", 281 static_cast<void*>(process_sp.get()), 282 static_cast<void*>(thread_sp.get())); 283 284 return sb_thread; 285 } 286 287 SBThread 288 SBProcess::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context) 289 { 290 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 291 292 SBThread sb_thread; 293 ThreadSP thread_sp; 294 ProcessSP process_sp(GetSP()); 295 if (process_sp) 296 { 297 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 298 thread_sp = process_sp->CreateOSPluginThread(tid, context); 299 sb_thread.SetThread (thread_sp); 300 } 301 302 if (log) 303 log->Printf ("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64 ", context=0x%" PRIx64 ") => SBThread(%p)", 304 static_cast<void*>(process_sp.get()), tid, context, 305 static_cast<void*>(thread_sp.get())); 306 307 return sb_thread; 308 } 309 310 SBTarget 311 SBProcess::GetTarget() const 312 { 313 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 314 315 SBTarget sb_target; 316 TargetSP target_sp; 317 ProcessSP process_sp(GetSP()); 318 if (process_sp) 319 { 320 target_sp = process_sp->GetTarget().shared_from_this(); 321 sb_target.SetSP (target_sp); 322 } 323 324 if (log) 325 log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", 326 static_cast<void*>(process_sp.get()), 327 static_cast<void*>(target_sp.get())); 328 329 return sb_target; 330 } 331 332 333 size_t 334 SBProcess::PutSTDIN (const char *src, size_t src_len) 335 { 336 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 337 338 size_t ret_val = 0; 339 ProcessSP process_sp(GetSP()); 340 if (process_sp) 341 { 342 Error error; 343 ret_val = process_sp->PutSTDIN (src, src_len, error); 344 } 345 346 if (log) 347 log->Printf("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%" PRIu64 ") => %" PRIu64, 348 static_cast<void*>(process_sp.get()), src, 349 static_cast<uint64_t>(src_len), 350 static_cast<uint64_t>(ret_val)); 351 352 return ret_val; 353 } 354 355 size_t 356 SBProcess::GetSTDOUT (char *dst, size_t dst_len) const 357 { 358 size_t bytes_read = 0; 359 ProcessSP process_sp(GetSP()); 360 if (process_sp) 361 { 362 Error error; 363 bytes_read = process_sp->GetSTDOUT (dst, dst_len, error); 364 } 365 366 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 367 if (log) 368 log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 369 static_cast<void*>(process_sp.get()), 370 static_cast<int>(bytes_read), dst, 371 static_cast<uint64_t>(dst_len), 372 static_cast<uint64_t>(bytes_read)); 373 374 return bytes_read; 375 } 376 377 size_t 378 SBProcess::GetSTDERR (char *dst, size_t dst_len) const 379 { 380 size_t bytes_read = 0; 381 ProcessSP process_sp(GetSP()); 382 if (process_sp) 383 { 384 Error error; 385 bytes_read = process_sp->GetSTDERR (dst, dst_len, error); 386 } 387 388 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 389 if (log) 390 log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 391 static_cast<void*>(process_sp.get()), 392 static_cast<int>(bytes_read), dst, 393 static_cast<uint64_t>(dst_len), 394 static_cast<uint64_t>(bytes_read)); 395 396 return bytes_read; 397 } 398 399 size_t 400 SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const 401 { 402 size_t bytes_read = 0; 403 ProcessSP process_sp(GetSP()); 404 if (process_sp) 405 { 406 Error error; 407 bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error); 408 } 409 410 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 411 if (log) 412 log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64, 413 static_cast<void*>(process_sp.get()), 414 static_cast<int>(bytes_read), dst, 415 static_cast<uint64_t>(dst_len), 416 static_cast<uint64_t>(bytes_read)); 417 418 return bytes_read; 419 } 420 421 void 422 SBProcess::ReportEventState (const SBEvent &event, FILE *out) const 423 { 424 if (out == NULL) 425 return; 426 427 ProcessSP process_sp(GetSP()); 428 if (process_sp) 429 { 430 const StateType event_state = SBProcess::GetStateFromEvent (event); 431 char message[1024]; 432 int message_len = ::snprintf (message, 433 sizeof (message), 434 "Process %" PRIu64 " %s\n", 435 process_sp->GetID(), 436 SBDebugger::StateAsCString (event_state)); 437 438 if (message_len > 0) 439 ::fwrite (message, 1, message_len, out); 440 } 441 } 442 443 void 444 SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) 445 { 446 ProcessSP process_sp(GetSP()); 447 if (process_sp) 448 { 449 const StateType event_state = SBProcess::GetStateFromEvent (event); 450 char message[1024]; 451 ::snprintf (message, 452 sizeof (message), 453 "Process %" PRIu64 " %s\n", 454 process_sp->GetID(), 455 SBDebugger::StateAsCString (event_state)); 456 457 result.AppendMessage (message); 458 } 459 } 460 461 bool 462 SBProcess::SetSelectedThread (const SBThread &thread) 463 { 464 ProcessSP process_sp(GetSP()); 465 if (process_sp) 466 { 467 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 468 return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); 469 } 470 return false; 471 } 472 473 bool 474 SBProcess::SetSelectedThreadByID (lldb::tid_t tid) 475 { 476 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 477 478 bool ret_val = false; 479 ProcessSP process_sp(GetSP()); 480 if (process_sp) 481 { 482 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 483 ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid); 484 } 485 486 if (log) 487 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s", 488 static_cast<void*>(process_sp.get()), tid, 489 (ret_val ? "true" : "false")); 490 491 return ret_val; 492 } 493 494 bool 495 SBProcess::SetSelectedThreadByIndexID (uint32_t index_id) 496 { 497 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 498 499 bool ret_val = false; 500 ProcessSP process_sp(GetSP()); 501 if (process_sp) 502 { 503 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 504 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id); 505 } 506 507 if (log) 508 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s", 509 static_cast<void*>(process_sp.get()), index_id, 510 (ret_val ? "true" : "false")); 511 512 return ret_val; 513 } 514 515 SBThread 516 SBProcess::GetThreadAtIndex (size_t index) 517 { 518 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 519 520 SBThread sb_thread; 521 ThreadSP thread_sp; 522 ProcessSP process_sp(GetSP()); 523 if (process_sp) 524 { 525 Process::StopLocker stop_locker; 526 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 527 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 528 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); 529 sb_thread.SetThread (thread_sp); 530 } 531 532 if (log) 533 log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)", 534 static_cast<void*>(process_sp.get()), 535 static_cast<uint32_t>(index), 536 static_cast<void*>(thread_sp.get())); 537 538 return sb_thread; 539 } 540 541 uint32_t 542 SBProcess::GetNumQueues () 543 { 544 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 545 546 uint32_t num_queues = 0; 547 ProcessSP process_sp(GetSP()); 548 if (process_sp) 549 { 550 Process::StopLocker stop_locker; 551 552 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 553 num_queues = process_sp->GetQueueList().GetSize(); 554 } 555 556 if (log) 557 log->Printf ("SBProcess(%p)::GetNumQueues () => %d", 558 static_cast<void*>(process_sp.get()), num_queues); 559 560 return num_queues; 561 } 562 563 SBQueue 564 SBProcess::GetQueueAtIndex (size_t index) 565 { 566 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 567 568 SBQueue sb_queue; 569 QueueSP queue_sp; 570 ProcessSP process_sp(GetSP()); 571 if (process_sp) 572 { 573 Process::StopLocker stop_locker; 574 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 575 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index); 576 sb_queue.SetQueue (queue_sp); 577 } 578 579 if (log) 580 log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)", 581 static_cast<void*>(process_sp.get()), 582 static_cast<uint32_t>(index), 583 static_cast<void*>(queue_sp.get())); 584 585 return sb_queue; 586 } 587 588 589 uint32_t 590 SBProcess::GetStopID(bool include_expression_stops) 591 { 592 ProcessSP process_sp(GetSP()); 593 if (process_sp) 594 { 595 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 596 if (include_expression_stops) 597 return process_sp->GetStopID(); 598 else 599 return process_sp->GetLastNaturalStopID(); 600 } 601 return 0; 602 } 603 604 SBEvent 605 SBProcess::GetStopEventForStopID(uint32_t stop_id) 606 { 607 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 608 609 SBEvent sb_event; 610 EventSP event_sp; 611 ProcessSP process_sp(GetSP()); 612 if (process_sp) 613 { 614 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 615 event_sp = process_sp->GetStopEventForStopID(stop_id); 616 sb_event.reset(event_sp); 617 } 618 619 if (log) 620 log->Printf ("SBProcess(%p)::GetStopEventForStopID (stop_id=%" PRIu32 ") => SBEvent(%p)", 621 static_cast<void*>(process_sp.get()), 622 stop_id, 623 static_cast<void*>(event_sp.get())); 624 625 return sb_event; 626 } 627 628 StateType 629 SBProcess::GetState () 630 { 631 632 StateType ret_val = eStateInvalid; 633 ProcessSP process_sp(GetSP()); 634 if (process_sp) 635 { 636 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 637 ret_val = process_sp->GetState(); 638 } 639 640 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 641 if (log) 642 log->Printf ("SBProcess(%p)::GetState () => %s", 643 static_cast<void*>(process_sp.get()), 644 lldb_private::StateAsCString (ret_val)); 645 646 return ret_val; 647 } 648 649 650 int 651 SBProcess::GetExitStatus () 652 { 653 int exit_status = 0; 654 ProcessSP process_sp(GetSP()); 655 if (process_sp) 656 { 657 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 658 exit_status = process_sp->GetExitStatus (); 659 } 660 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 661 if (log) 662 log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", 663 static_cast<void*>(process_sp.get()), exit_status, 664 exit_status); 665 666 return exit_status; 667 } 668 669 const char * 670 SBProcess::GetExitDescription () 671 { 672 const char *exit_desc = NULL; 673 ProcessSP process_sp(GetSP()); 674 if (process_sp) 675 { 676 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 677 exit_desc = process_sp->GetExitDescription (); 678 } 679 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 680 if (log) 681 log->Printf ("SBProcess(%p)::GetExitDescription () => %s", 682 static_cast<void*>(process_sp.get()), exit_desc); 683 return exit_desc; 684 } 685 686 lldb::pid_t 687 SBProcess::GetProcessID () 688 { 689 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; 690 ProcessSP process_sp(GetSP()); 691 if (process_sp) 692 ret_val = process_sp->GetID(); 693 694 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 695 if (log) 696 log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, 697 static_cast<void*>(process_sp.get()), ret_val); 698 699 return ret_val; 700 } 701 702 uint32_t 703 SBProcess::GetUniqueID() 704 { 705 uint32_t ret_val = 0; 706 ProcessSP process_sp(GetSP()); 707 if (process_sp) 708 ret_val = process_sp->GetUniqueID(); 709 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 710 if (log) 711 log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, 712 static_cast<void*>(process_sp.get()), ret_val); 713 return ret_val; 714 } 715 716 ByteOrder 717 SBProcess::GetByteOrder () const 718 { 719 ByteOrder byteOrder = eByteOrderInvalid; 720 ProcessSP process_sp(GetSP()); 721 if (process_sp) 722 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); 723 724 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 725 if (log) 726 log->Printf ("SBProcess(%p)::GetByteOrder () => %d", 727 static_cast<void*>(process_sp.get()), byteOrder); 728 729 return byteOrder; 730 } 731 732 uint32_t 733 SBProcess::GetAddressByteSize () const 734 { 735 uint32_t size = 0; 736 ProcessSP process_sp(GetSP()); 737 if (process_sp) 738 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); 739 740 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 741 if (log) 742 log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", 743 static_cast<void*>(process_sp.get()), size); 744 745 return size; 746 } 747 748 SBError 749 SBProcess::Continue () 750 { 751 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 752 753 SBError sb_error; 754 ProcessSP process_sp(GetSP()); 755 756 if (log) 757 log->Printf ("SBProcess(%p)::Continue ()...", 758 static_cast<void*>(process_sp.get())); 759 760 if (process_sp) 761 { 762 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 763 764 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution ()) 765 sb_error.ref() = process_sp->Resume (); 766 else 767 sb_error.ref() = process_sp->ResumeSynchronous (NULL); 768 } 769 else 770 sb_error.SetErrorString ("SBProcess is invalid"); 771 772 if (log) 773 { 774 SBStream sstr; 775 sb_error.GetDescription (sstr); 776 log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", 777 static_cast<void*>(process_sp.get()), 778 static_cast<void*>(sb_error.get()), sstr.GetData()); 779 } 780 781 return sb_error; 782 } 783 784 785 SBError 786 SBProcess::Destroy () 787 { 788 SBError sb_error; 789 ProcessSP process_sp(GetSP()); 790 if (process_sp) 791 { 792 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 793 sb_error.SetError(process_sp->Destroy(false)); 794 } 795 else 796 sb_error.SetErrorString ("SBProcess is invalid"); 797 798 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 799 if (log) 800 { 801 SBStream sstr; 802 sb_error.GetDescription (sstr); 803 log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", 804 static_cast<void*>(process_sp.get()), 805 static_cast<void*>(sb_error.get()), sstr.GetData()); 806 } 807 808 return sb_error; 809 } 810 811 812 SBError 813 SBProcess::Stop () 814 { 815 SBError sb_error; 816 ProcessSP process_sp(GetSP()); 817 if (process_sp) 818 { 819 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 820 sb_error.SetError (process_sp->Halt()); 821 } 822 else 823 sb_error.SetErrorString ("SBProcess is invalid"); 824 825 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 826 if (log) 827 { 828 SBStream sstr; 829 sb_error.GetDescription (sstr); 830 log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", 831 static_cast<void*>(process_sp.get()), 832 static_cast<void*>(sb_error.get()), sstr.GetData()); 833 } 834 835 return sb_error; 836 } 837 838 SBError 839 SBProcess::Kill () 840 { 841 SBError sb_error; 842 ProcessSP process_sp(GetSP()); 843 if (process_sp) 844 { 845 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 846 sb_error.SetError (process_sp->Destroy(true)); 847 } 848 else 849 sb_error.SetErrorString ("SBProcess is invalid"); 850 851 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 852 if (log) 853 { 854 SBStream sstr; 855 sb_error.GetDescription (sstr); 856 log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", 857 static_cast<void*>(process_sp.get()), 858 static_cast<void*>(sb_error.get()), sstr.GetData()); 859 } 860 861 return sb_error; 862 } 863 864 SBError 865 SBProcess::Detach () 866 { 867 // FIXME: This should come from a process default. 868 bool keep_stopped = false; 869 return Detach (keep_stopped); 870 } 871 872 SBError 873 SBProcess::Detach (bool keep_stopped) 874 { 875 SBError sb_error; 876 ProcessSP process_sp(GetSP()); 877 if (process_sp) 878 { 879 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 880 sb_error.SetError (process_sp->Detach(keep_stopped)); 881 } 882 else 883 sb_error.SetErrorString ("SBProcess is invalid"); 884 885 return sb_error; 886 } 887 888 SBError 889 SBProcess::Signal (int signo) 890 { 891 SBError sb_error; 892 ProcessSP process_sp(GetSP()); 893 if (process_sp) 894 { 895 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 896 sb_error.SetError (process_sp->Signal (signo)); 897 } 898 else 899 sb_error.SetErrorString ("SBProcess is invalid"); 900 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 901 if (log) 902 { 903 SBStream sstr; 904 sb_error.GetDescription (sstr); 905 log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", 906 static_cast<void*>(process_sp.get()), signo, 907 static_cast<void*>(sb_error.get()), sstr.GetData()); 908 } 909 return sb_error; 910 } 911 912 SBUnixSignals 913 SBProcess::GetUnixSignals() 914 { 915 SBUnixSignals sb_unix_signals; 916 ProcessSP process_sp(GetSP()); 917 if (process_sp) 918 { 919 sb_unix_signals.SetSP(process_sp); 920 } 921 922 return sb_unix_signals; 923 } 924 925 void 926 SBProcess::SendAsyncInterrupt () 927 { 928 ProcessSP process_sp(GetSP()); 929 if (process_sp) 930 { 931 process_sp->SendAsyncInterrupt (); 932 } 933 } 934 935 SBThread 936 SBProcess::GetThreadByID (tid_t tid) 937 { 938 SBThread sb_thread; 939 ThreadSP thread_sp; 940 ProcessSP process_sp(GetSP()); 941 if (process_sp) 942 { 943 Process::StopLocker stop_locker; 944 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 945 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 946 thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update); 947 sb_thread.SetThread (thread_sp); 948 } 949 950 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 951 if (log) 952 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)", 953 static_cast<void*>(process_sp.get()), tid, 954 static_cast<void*>(thread_sp.get())); 955 956 return sb_thread; 957 } 958 959 SBThread 960 SBProcess::GetThreadByIndexID (uint32_t index_id) 961 { 962 SBThread sb_thread; 963 ThreadSP thread_sp; 964 ProcessSP process_sp(GetSP()); 965 if (process_sp) 966 { 967 Process::StopLocker stop_locker; 968 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 969 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 970 thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update); 971 sb_thread.SetThread (thread_sp); 972 } 973 974 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 975 if (log) 976 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", 977 static_cast<void*>(process_sp.get()), index_id, 978 static_cast<void*>(thread_sp.get())); 979 980 return sb_thread; 981 } 982 983 StateType 984 SBProcess::GetStateFromEvent (const SBEvent &event) 985 { 986 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 987 988 StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get()); 989 990 if (log) 991 log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", 992 static_cast<void*>(event.get()), 993 lldb_private::StateAsCString (ret_val)); 994 995 return ret_val; 996 } 997 998 bool 999 SBProcess::GetRestartedFromEvent (const SBEvent &event) 1000 { 1001 return Process::ProcessEventData::GetRestartedFromEvent (event.get()); 1002 } 1003 1004 size_t 1005 SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event) 1006 { 1007 return Process::ProcessEventData::GetNumRestartedReasons(event.get()); 1008 } 1009 1010 const char * 1011 SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx) 1012 { 1013 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx); 1014 } 1015 1016 SBProcess 1017 SBProcess::GetProcessFromEvent (const SBEvent &event) 1018 { 1019 SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); 1020 return process; 1021 } 1022 1023 bool 1024 SBProcess::GetInterruptedFromEvent (const SBEvent &event) 1025 { 1026 return Process::ProcessEventData::GetInterruptedFromEvent(event.get()); 1027 } 1028 1029 bool 1030 SBProcess::EventIsProcessEvent (const SBEvent &event) 1031 { 1032 return event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass(); 1033 } 1034 1035 SBBroadcaster 1036 SBProcess::GetBroadcaster () const 1037 { 1038 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1039 1040 ProcessSP process_sp(GetSP()); 1041 1042 SBBroadcaster broadcaster(process_sp.get(), false); 1043 1044 if (log) 1045 log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", 1046 static_cast<void*>(process_sp.get()), 1047 static_cast<void*>(broadcaster.get())); 1048 1049 return broadcaster; 1050 } 1051 1052 const char * 1053 SBProcess::GetBroadcasterClass () 1054 { 1055 return Process::GetStaticBroadcasterClass().AsCString(); 1056 } 1057 1058 size_t 1059 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) 1060 { 1061 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1062 1063 size_t bytes_read = 0; 1064 1065 ProcessSP process_sp(GetSP()); 1066 1067 if (log) 1068 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...", 1069 static_cast<void*>(process_sp.get()), addr, 1070 static_cast<void*>(dst), static_cast<uint64_t>(dst_len), 1071 static_cast<void*>(sb_error.get())); 1072 1073 if (process_sp) 1074 { 1075 Process::StopLocker stop_locker; 1076 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1077 { 1078 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1079 bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref()); 1080 } 1081 else 1082 { 1083 if (log) 1084 log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", 1085 static_cast<void*>(process_sp.get())); 1086 sb_error.SetErrorString("process is running"); 1087 } 1088 } 1089 else 1090 { 1091 sb_error.SetErrorString ("SBProcess is invalid"); 1092 } 1093 1094 if (log) 1095 { 1096 SBStream sstr; 1097 sb_error.GetDescription (sstr); 1098 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64, 1099 static_cast<void*>(process_sp.get()), addr, 1100 static_cast<void*>(dst), static_cast<uint64_t>(dst_len), 1101 static_cast<void*>(sb_error.get()), sstr.GetData(), 1102 static_cast<uint64_t>(bytes_read)); 1103 } 1104 1105 return bytes_read; 1106 } 1107 1108 size_t 1109 SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) 1110 { 1111 size_t bytes_read = 0; 1112 ProcessSP process_sp(GetSP()); 1113 if (process_sp) 1114 { 1115 Process::StopLocker stop_locker; 1116 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1117 { 1118 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1119 bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref()); 1120 } 1121 else 1122 { 1123 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1124 if (log) 1125 log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", 1126 static_cast<void*>(process_sp.get())); 1127 sb_error.SetErrorString("process is running"); 1128 } 1129 } 1130 else 1131 { 1132 sb_error.SetErrorString ("SBProcess is invalid"); 1133 } 1134 return bytes_read; 1135 } 1136 1137 uint64_t 1138 SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) 1139 { 1140 uint64_t value = 0; 1141 ProcessSP process_sp(GetSP()); 1142 if (process_sp) 1143 { 1144 Process::StopLocker stop_locker; 1145 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1146 { 1147 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1148 value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref()); 1149 } 1150 else 1151 { 1152 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1153 if (log) 1154 log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", 1155 static_cast<void*>(process_sp.get())); 1156 sb_error.SetErrorString("process is running"); 1157 } 1158 } 1159 else 1160 { 1161 sb_error.SetErrorString ("SBProcess is invalid"); 1162 } 1163 return value; 1164 } 1165 1166 lldb::addr_t 1167 SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) 1168 { 1169 lldb::addr_t ptr = LLDB_INVALID_ADDRESS; 1170 ProcessSP process_sp(GetSP()); 1171 if (process_sp) 1172 { 1173 Process::StopLocker stop_locker; 1174 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1175 { 1176 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1177 ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref()); 1178 } 1179 else 1180 { 1181 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1182 if (log) 1183 log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", 1184 static_cast<void*>(process_sp.get())); 1185 sb_error.SetErrorString("process is running"); 1186 } 1187 } 1188 else 1189 { 1190 sb_error.SetErrorString ("SBProcess is invalid"); 1191 } 1192 return ptr; 1193 } 1194 1195 size_t 1196 SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error) 1197 { 1198 size_t bytes_written = 0; 1199 1200 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1201 1202 ProcessSP process_sp(GetSP()); 1203 1204 if (log) 1205 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...", 1206 static_cast<void*>(process_sp.get()), addr, 1207 static_cast<const void*>(src), 1208 static_cast<uint64_t>(src_len), 1209 static_cast<void*>(sb_error.get())); 1210 1211 if (process_sp) 1212 { 1213 Process::StopLocker stop_locker; 1214 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1215 { 1216 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1217 bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref()); 1218 } 1219 else 1220 { 1221 if (log) 1222 log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", 1223 static_cast<void*>(process_sp.get())); 1224 sb_error.SetErrorString("process is running"); 1225 } 1226 } 1227 1228 if (log) 1229 { 1230 SBStream sstr; 1231 sb_error.GetDescription (sstr); 1232 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64, 1233 static_cast<void*>(process_sp.get()), addr, 1234 static_cast<const void*>(src), 1235 static_cast<uint64_t>(src_len), 1236 static_cast<void*>(sb_error.get()), sstr.GetData(), 1237 static_cast<uint64_t>(bytes_written)); 1238 } 1239 1240 return bytes_written; 1241 } 1242 1243 bool 1244 SBProcess::GetDescription (SBStream &description) 1245 { 1246 Stream &strm = description.ref(); 1247 1248 ProcessSP process_sp(GetSP()); 1249 if (process_sp) 1250 { 1251 char path[PATH_MAX]; 1252 GetTarget().GetExecutable().GetPath (path, sizeof(path)); 1253 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 1254 const char *exe_name = NULL; 1255 if (exe_module) 1256 exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); 1257 1258 strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", 1259 process_sp->GetID(), 1260 lldb_private::StateAsCString (GetState()), 1261 GetNumThreads(), 1262 exe_name ? ", executable = " : "", 1263 exe_name ? exe_name : ""); 1264 } 1265 else 1266 strm.PutCString ("No value"); 1267 1268 return true; 1269 } 1270 1271 uint32_t 1272 SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const 1273 { 1274 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1275 1276 uint32_t num = 0; 1277 ProcessSP process_sp(GetSP()); 1278 if (process_sp) 1279 { 1280 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1281 sb_error.SetError(process_sp->GetWatchpointSupportInfo (num)); 1282 if (log) 1283 log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u", 1284 static_cast<void*>(process_sp.get()), num); 1285 } 1286 else 1287 { 1288 sb_error.SetErrorString ("SBProcess is invalid"); 1289 } 1290 return num; 1291 } 1292 1293 uint32_t 1294 SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) 1295 { 1296 ProcessSP process_sp(GetSP()); 1297 if (process_sp) 1298 { 1299 Process::StopLocker stop_locker; 1300 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1301 { 1302 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1303 return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); 1304 } 1305 else 1306 { 1307 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1308 if (log) 1309 log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", 1310 static_cast<void*>(process_sp.get())); 1311 sb_error.SetErrorString("process is running"); 1312 } 1313 } 1314 return LLDB_INVALID_IMAGE_TOKEN; 1315 } 1316 1317 lldb::SBError 1318 SBProcess::UnloadImage (uint32_t image_token) 1319 { 1320 lldb::SBError sb_error; 1321 ProcessSP process_sp(GetSP()); 1322 if (process_sp) 1323 { 1324 Process::StopLocker stop_locker; 1325 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1326 { 1327 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1328 sb_error.SetError (process_sp->UnloadImage (image_token)); 1329 } 1330 else 1331 { 1332 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1333 if (log) 1334 log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", 1335 static_cast<void*>(process_sp.get())); 1336 sb_error.SetErrorString("process is running"); 1337 } 1338 } 1339 else 1340 sb_error.SetErrorString("invalid process"); 1341 return sb_error; 1342 } 1343 1344 lldb::SBError 1345 SBProcess::SendEventData (const char *event_data) 1346 { 1347 lldb::SBError sb_error; 1348 ProcessSP process_sp(GetSP()); 1349 if (process_sp) 1350 { 1351 Process::StopLocker stop_locker; 1352 if (stop_locker.TryLock(&process_sp->GetRunLock())) 1353 { 1354 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); 1355 sb_error.SetError (process_sp->SendEventData (event_data)); 1356 } 1357 else 1358 { 1359 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1360 if (log) 1361 log->Printf ("SBProcess(%p)::SendEventData() => error: process is running", 1362 static_cast<void*>(process_sp.get())); 1363 sb_error.SetErrorString("process is running"); 1364 } 1365 } 1366 else 1367 sb_error.SetErrorString("invalid process"); 1368 return sb_error; 1369 } 1370 1371 uint32_t 1372 SBProcess::GetNumExtendedBacktraceTypes () 1373 { 1374 ProcessSP process_sp(GetSP()); 1375 if (process_sp && process_sp->GetSystemRuntime()) 1376 { 1377 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1378 return runtime->GetExtendedBacktraceTypes().size(); 1379 } 1380 return 0; 1381 } 1382 1383 const char * 1384 SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx) 1385 { 1386 ProcessSP process_sp(GetSP()); 1387 if (process_sp && process_sp->GetSystemRuntime()) 1388 { 1389 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1390 const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes(); 1391 if (idx < names.size()) 1392 { 1393 return names[idx].AsCString(); 1394 } 1395 else 1396 { 1397 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1398 if (log) 1399 log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds", 1400 static_cast<void*>(process_sp.get())); 1401 } 1402 } 1403 return NULL; 1404 } 1405 1406 SBThreadCollection 1407 SBProcess::GetHistoryThreads (addr_t addr) 1408 { 1409 ProcessSP process_sp(GetSP()); 1410 SBThreadCollection threads; 1411 if (process_sp) 1412 { 1413 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr)); 1414 } 1415 return threads; 1416 } 1417 1418 bool 1419 SBProcess::IsInstrumentationRuntimePresent(InstrumentationRuntimeType type) 1420 { 1421 ProcessSP process_sp(GetSP()); 1422 if (! process_sp) 1423 return false; 1424 1425 InstrumentationRuntimeSP runtime_sp = process_sp->GetInstrumentationRuntime(type); 1426 1427 if (! runtime_sp.get()) 1428 return false; 1429 1430 return runtime_sp->IsActive(); 1431 } 1432