1 //===-- SBTarget.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/lldb-python.h" 11 12 #include "lldb/API/SBTarget.h" 13 14 #include "lldb/lldb-public.h" 15 16 #include "lldb/API/SBDebugger.h" 17 #include "lldb/API/SBBreakpoint.h" 18 #include "lldb/API/SBExpressionOptions.h" 19 #include "lldb/API/SBFileSpec.h" 20 #include "lldb/API/SBListener.h" 21 #include "lldb/API/SBModule.h" 22 #include "lldb/API/SBModuleSpec.h" 23 #include "lldb/API/SBSourceManager.h" 24 #include "lldb/API/SBProcess.h" 25 #include "lldb/API/SBStream.h" 26 #include "lldb/API/SBSymbolContextList.h" 27 #include "lldb/Breakpoint/BreakpointID.h" 28 #include "lldb/Breakpoint/BreakpointIDList.h" 29 #include "lldb/Breakpoint/BreakpointList.h" 30 #include "lldb/Breakpoint/BreakpointLocation.h" 31 #include "lldb/Core/Address.h" 32 #include "lldb/Core/AddressResolver.h" 33 #include "lldb/Core/AddressResolverName.h" 34 #include "lldb/Core/ArchSpec.h" 35 #include "lldb/Core/Debugger.h" 36 #include "lldb/Core/Disassembler.h" 37 #include "lldb/Core/Log.h" 38 #include "lldb/Core/Module.h" 39 #include "lldb/Core/ModuleSpec.h" 40 #include "lldb/Core/RegularExpression.h" 41 #include "lldb/Core/SearchFilter.h" 42 #include "lldb/Core/Section.h" 43 #include "lldb/Core/STLUtils.h" 44 #include "lldb/Core/ValueObjectConstResult.h" 45 #include "lldb/Core/ValueObjectList.h" 46 #include "lldb/Core/ValueObjectVariable.h" 47 #include "lldb/Host/FileSpec.h" 48 #include "lldb/Host/Host.h" 49 #include "lldb/Interpreter/Args.h" 50 #include "lldb/Symbol/ObjectFile.h" 51 #include "lldb/Symbol/SymbolVendor.h" 52 #include "lldb/Symbol/VariableList.h" 53 #include "lldb/Target/LanguageRuntime.h" 54 #include "lldb/Target/Process.h" 55 56 #include "lldb/Target/Target.h" 57 #include "lldb/Target/TargetList.h" 58 59 #include "lldb/Interpreter/CommandReturnObject.h" 60 #include "../source/Commands/CommandObjectBreakpoint.h" 61 #include "llvm/Support/Regex.h" 62 63 64 using namespace lldb; 65 using namespace lldb_private; 66 67 #define DEFAULT_DISASM_BYTE_SIZE 32 68 69 SBLaunchInfo::SBLaunchInfo (const char **argv) : 70 m_opaque_sp(new ProcessLaunchInfo()) 71 { 72 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR); 73 if (argv && argv[0]) 74 m_opaque_sp->GetArguments().SetArguments(argv); 75 } 76 77 SBLaunchInfo::~SBLaunchInfo() 78 { 79 } 80 81 lldb_private::ProcessLaunchInfo & 82 SBLaunchInfo::ref () 83 { 84 return *m_opaque_sp; 85 } 86 87 88 uint32_t 89 SBLaunchInfo::GetUserID() 90 { 91 return m_opaque_sp->GetUserID(); 92 } 93 94 uint32_t 95 SBLaunchInfo::GetGroupID() 96 { 97 return m_opaque_sp->GetGroupID(); 98 } 99 100 bool 101 SBLaunchInfo::UserIDIsValid () 102 { 103 return m_opaque_sp->UserIDIsValid(); 104 } 105 106 bool 107 SBLaunchInfo::GroupIDIsValid () 108 { 109 return m_opaque_sp->GroupIDIsValid(); 110 } 111 112 void 113 SBLaunchInfo::SetUserID (uint32_t uid) 114 { 115 m_opaque_sp->SetUserID (uid); 116 } 117 118 void 119 SBLaunchInfo::SetGroupID (uint32_t gid) 120 { 121 m_opaque_sp->SetGroupID (gid); 122 } 123 124 SBFileSpec 125 SBLaunchInfo::GetExecutableFile () 126 { 127 return SBFileSpec (m_opaque_sp->GetExecutableFile()); 128 } 129 130 void 131 SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg) 132 { 133 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg); 134 } 135 136 SBListener 137 SBLaunchInfo::GetListener () 138 { 139 return SBListener(m_opaque_sp->GetListener()); 140 } 141 142 void 143 SBLaunchInfo::SetListener (SBListener &listener) 144 { 145 m_opaque_sp->SetListener(listener.GetSP()); 146 } 147 148 uint32_t 149 SBLaunchInfo::GetNumArguments () 150 { 151 return m_opaque_sp->GetArguments().GetArgumentCount(); 152 } 153 154 const char * 155 SBLaunchInfo::GetArgumentAtIndex (uint32_t idx) 156 { 157 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); 158 } 159 160 void 161 SBLaunchInfo::SetArguments (const char **argv, bool append) 162 { 163 if (append) 164 { 165 if (argv) 166 m_opaque_sp->GetArguments().AppendArguments(argv); 167 } 168 else 169 { 170 if (argv) 171 m_opaque_sp->GetArguments().SetArguments(argv); 172 else 173 m_opaque_sp->GetArguments().Clear(); 174 } 175 } 176 177 uint32_t 178 SBLaunchInfo::GetNumEnvironmentEntries () 179 { 180 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); 181 } 182 183 const char * 184 SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx) 185 { 186 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); 187 } 188 189 void 190 SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append) 191 { 192 if (append) 193 { 194 if (envp) 195 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp); 196 } 197 else 198 { 199 if (envp) 200 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp); 201 else 202 m_opaque_sp->GetEnvironmentEntries().Clear(); 203 } 204 } 205 206 void 207 SBLaunchInfo::Clear () 208 { 209 m_opaque_sp->Clear(); 210 } 211 212 const char * 213 SBLaunchInfo::GetWorkingDirectory () const 214 { 215 return m_opaque_sp->GetWorkingDirectory(); 216 } 217 218 void 219 SBLaunchInfo::SetWorkingDirectory (const char *working_dir) 220 { 221 m_opaque_sp->SetWorkingDirectory(working_dir); 222 } 223 224 uint32_t 225 SBLaunchInfo::GetLaunchFlags () 226 { 227 return m_opaque_sp->GetFlags().Get(); 228 } 229 230 void 231 SBLaunchInfo::SetLaunchFlags (uint32_t flags) 232 { 233 m_opaque_sp->GetFlags().Reset(flags); 234 } 235 236 const char * 237 SBLaunchInfo::GetProcessPluginName () 238 { 239 return m_opaque_sp->GetProcessPluginName(); 240 } 241 242 void 243 SBLaunchInfo::SetProcessPluginName (const char *plugin_name) 244 { 245 return m_opaque_sp->SetProcessPluginName (plugin_name); 246 } 247 248 const char * 249 SBLaunchInfo::GetShell () 250 { 251 // Constify this string so that it is saved in the string pool. Otherwise 252 // it would be freed when this function goes out of scope. 253 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str()); 254 return shell.AsCString(); 255 } 256 257 void 258 SBLaunchInfo::SetShell (const char * path) 259 { 260 m_opaque_sp->SetShell (FileSpec(path, false)); 261 } 262 263 uint32_t 264 SBLaunchInfo::GetResumeCount () 265 { 266 return m_opaque_sp->GetResumeCount(); 267 } 268 269 void 270 SBLaunchInfo::SetResumeCount (uint32_t c) 271 { 272 m_opaque_sp->SetResumeCount (c); 273 } 274 275 bool 276 SBLaunchInfo::AddCloseFileAction (int fd) 277 { 278 return m_opaque_sp->AppendCloseFileAction(fd); 279 } 280 281 bool 282 SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd) 283 { 284 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); 285 } 286 287 bool 288 SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write) 289 { 290 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write); 291 } 292 293 bool 294 SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write) 295 { 296 return m_opaque_sp->AppendSuppressFileAction(fd, read, write); 297 } 298 299 void 300 SBLaunchInfo::SetLaunchEventData (const char *data) 301 { 302 m_opaque_sp->SetLaunchEventData (data); 303 } 304 305 const char * 306 SBLaunchInfo::GetLaunchEventData () const 307 { 308 return m_opaque_sp->GetLaunchEventData (); 309 } 310 311 void 312 SBLaunchInfo::SetDetachOnError (bool enable) 313 { 314 m_opaque_sp->SetDetachOnError (enable); 315 } 316 317 bool 318 SBLaunchInfo::GetDetachOnError () const 319 { 320 return m_opaque_sp->GetDetachOnError (); 321 } 322 323 SBAttachInfo::SBAttachInfo () : 324 m_opaque_sp (new ProcessAttachInfo()) 325 { 326 } 327 328 SBAttachInfo::SBAttachInfo (lldb::pid_t pid) : 329 m_opaque_sp (new ProcessAttachInfo()) 330 { 331 m_opaque_sp->SetProcessID (pid); 332 } 333 334 SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) : 335 m_opaque_sp (new ProcessAttachInfo()) 336 { 337 if (path && path[0]) 338 m_opaque_sp->GetExecutableFile().SetFile(path, false); 339 m_opaque_sp->SetWaitForLaunch (wait_for); 340 } 341 342 SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) : 343 m_opaque_sp (new ProcessAttachInfo()) 344 { 345 *m_opaque_sp = *rhs.m_opaque_sp; 346 } 347 348 SBAttachInfo::~SBAttachInfo() 349 { 350 } 351 352 lldb_private::ProcessAttachInfo & 353 SBAttachInfo::ref () 354 { 355 return *m_opaque_sp; 356 } 357 358 SBAttachInfo & 359 SBAttachInfo::operator = (const SBAttachInfo &rhs) 360 { 361 if (this != &rhs) 362 *m_opaque_sp = *rhs.m_opaque_sp; 363 return *this; 364 } 365 366 lldb::pid_t 367 SBAttachInfo::GetProcessID () 368 { 369 return m_opaque_sp->GetProcessID(); 370 } 371 372 void 373 SBAttachInfo::SetProcessID (lldb::pid_t pid) 374 { 375 m_opaque_sp->SetProcessID (pid); 376 } 377 378 379 uint32_t 380 SBAttachInfo::GetResumeCount () 381 { 382 return m_opaque_sp->GetResumeCount(); 383 } 384 385 void 386 SBAttachInfo::SetResumeCount (uint32_t c) 387 { 388 m_opaque_sp->SetResumeCount (c); 389 } 390 391 const char * 392 SBAttachInfo::GetProcessPluginName () 393 { 394 return m_opaque_sp->GetProcessPluginName(); 395 } 396 397 void 398 SBAttachInfo::SetProcessPluginName (const char *plugin_name) 399 { 400 return m_opaque_sp->SetProcessPluginName (plugin_name); 401 } 402 403 void 404 SBAttachInfo::SetExecutable (const char *path) 405 { 406 if (path && path[0]) 407 m_opaque_sp->GetExecutableFile().SetFile(path, false); 408 else 409 m_opaque_sp->GetExecutableFile().Clear(); 410 } 411 412 void 413 SBAttachInfo::SetExecutable (SBFileSpec exe_file) 414 { 415 if (exe_file.IsValid()) 416 m_opaque_sp->GetExecutableFile() = exe_file.ref(); 417 else 418 m_opaque_sp->GetExecutableFile().Clear(); 419 } 420 421 bool 422 SBAttachInfo::GetWaitForLaunch () 423 { 424 return m_opaque_sp->GetWaitForLaunch(); 425 } 426 427 void 428 SBAttachInfo::SetWaitForLaunch (bool b) 429 { 430 m_opaque_sp->SetWaitForLaunch (b); 431 } 432 433 bool 434 SBAttachInfo::GetIgnoreExisting () 435 { 436 return m_opaque_sp->GetIgnoreExisting(); 437 } 438 439 void 440 SBAttachInfo::SetIgnoreExisting (bool b) 441 { 442 m_opaque_sp->SetIgnoreExisting (b); 443 } 444 445 uint32_t 446 SBAttachInfo::GetUserID() 447 { 448 return m_opaque_sp->GetUserID(); 449 } 450 451 uint32_t 452 SBAttachInfo::GetGroupID() 453 { 454 return m_opaque_sp->GetGroupID(); 455 } 456 457 bool 458 SBAttachInfo::UserIDIsValid () 459 { 460 return m_opaque_sp->UserIDIsValid(); 461 } 462 463 bool 464 SBAttachInfo::GroupIDIsValid () 465 { 466 return m_opaque_sp->GroupIDIsValid(); 467 } 468 469 void 470 SBAttachInfo::SetUserID (uint32_t uid) 471 { 472 m_opaque_sp->SetUserID (uid); 473 } 474 475 void 476 SBAttachInfo::SetGroupID (uint32_t gid) 477 { 478 m_opaque_sp->SetGroupID (gid); 479 } 480 481 uint32_t 482 SBAttachInfo::GetEffectiveUserID() 483 { 484 return m_opaque_sp->GetEffectiveUserID(); 485 } 486 487 uint32_t 488 SBAttachInfo::GetEffectiveGroupID() 489 { 490 return m_opaque_sp->GetEffectiveGroupID(); 491 } 492 493 bool 494 SBAttachInfo::EffectiveUserIDIsValid () 495 { 496 return m_opaque_sp->EffectiveUserIDIsValid(); 497 } 498 499 bool 500 SBAttachInfo::EffectiveGroupIDIsValid () 501 { 502 return m_opaque_sp->EffectiveGroupIDIsValid (); 503 } 504 505 void 506 SBAttachInfo::SetEffectiveUserID (uint32_t uid) 507 { 508 m_opaque_sp->SetEffectiveUserID(uid); 509 } 510 511 void 512 SBAttachInfo::SetEffectiveGroupID (uint32_t gid) 513 { 514 m_opaque_sp->SetEffectiveGroupID(gid); 515 } 516 517 lldb::pid_t 518 SBAttachInfo::GetParentProcessID () 519 { 520 return m_opaque_sp->GetParentProcessID(); 521 } 522 523 void 524 SBAttachInfo::SetParentProcessID (lldb::pid_t pid) 525 { 526 m_opaque_sp->SetParentProcessID (pid); 527 } 528 529 bool 530 SBAttachInfo::ParentProcessIDIsValid() 531 { 532 return m_opaque_sp->ParentProcessIDIsValid(); 533 } 534 535 SBListener 536 SBAttachInfo::GetListener () 537 { 538 return SBListener(m_opaque_sp->GetListener()); 539 } 540 541 void 542 SBAttachInfo::SetListener (SBListener &listener) 543 { 544 m_opaque_sp->SetListener(listener.GetSP()); 545 } 546 547 //---------------------------------------------------------------------- 548 // SBTarget constructor 549 //---------------------------------------------------------------------- 550 SBTarget::SBTarget () : 551 m_opaque_sp () 552 { 553 } 554 555 SBTarget::SBTarget (const SBTarget& rhs) : 556 m_opaque_sp (rhs.m_opaque_sp) 557 { 558 } 559 560 SBTarget::SBTarget(const TargetSP& target_sp) : 561 m_opaque_sp (target_sp) 562 { 563 } 564 565 const SBTarget& 566 SBTarget::operator = (const SBTarget& rhs) 567 { 568 if (this != &rhs) 569 m_opaque_sp = rhs.m_opaque_sp; 570 return *this; 571 } 572 573 //---------------------------------------------------------------------- 574 // Destructor 575 //---------------------------------------------------------------------- 576 SBTarget::~SBTarget() 577 { 578 } 579 580 const char * 581 SBTarget::GetBroadcasterClassName () 582 { 583 return Target::GetStaticBroadcasterClass().AsCString(); 584 } 585 586 bool 587 SBTarget::IsValid () const 588 { 589 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid(); 590 } 591 592 SBProcess 593 SBTarget::GetProcess () 594 { 595 SBProcess sb_process; 596 ProcessSP process_sp; 597 TargetSP target_sp(GetSP()); 598 if (target_sp) 599 { 600 process_sp = target_sp->GetProcessSP(); 601 sb_process.SetSP (process_sp); 602 } 603 604 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 605 if (log) 606 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", 607 static_cast<void*>(target_sp.get()), 608 static_cast<void*>(process_sp.get())); 609 610 return sb_process; 611 } 612 613 SBPlatform 614 SBTarget::GetPlatform () 615 { 616 TargetSP target_sp(GetSP()); 617 if (!target_sp) 618 return SBPlatform(); 619 620 SBPlatform platform; 621 platform.m_opaque_sp = target_sp->GetPlatform(); 622 623 return platform; 624 } 625 626 SBDebugger 627 SBTarget::GetDebugger () const 628 { 629 SBDebugger debugger; 630 TargetSP target_sp(GetSP()); 631 if (target_sp) 632 debugger.reset (target_sp->GetDebugger().shared_from_this()); 633 return debugger; 634 } 635 636 SBProcess 637 SBTarget::LoadCore (const char *core_file) 638 { 639 SBProcess sb_process; 640 TargetSP target_sp(GetSP()); 641 if (target_sp) 642 { 643 FileSpec filespec(core_file, true); 644 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(), 645 NULL, 646 &filespec)); 647 if (process_sp) 648 { 649 process_sp->LoadCore(); 650 sb_process.SetSP (process_sp); 651 } 652 } 653 return sb_process; 654 } 655 656 SBProcess 657 SBTarget::LaunchSimple 658 ( 659 char const **argv, 660 char const **envp, 661 const char *working_directory 662 ) 663 { 664 char *stdin_path = NULL; 665 char *stdout_path = NULL; 666 char *stderr_path = NULL; 667 uint32_t launch_flags = 0; 668 bool stop_at_entry = false; 669 SBError error; 670 SBListener listener = GetDebugger().GetListener(); 671 return Launch (listener, 672 argv, 673 envp, 674 stdin_path, 675 stdout_path, 676 stderr_path, 677 working_directory, 678 launch_flags, 679 stop_at_entry, 680 error); 681 } 682 683 SBError 684 SBTarget::Install() 685 { 686 SBError sb_error; 687 TargetSP target_sp(GetSP()); 688 if (target_sp) 689 { 690 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 691 sb_error.ref() = target_sp->Install(NULL); 692 } 693 return sb_error; 694 } 695 696 SBProcess 697 SBTarget::Launch 698 ( 699 SBListener &listener, 700 char const **argv, 701 char const **envp, 702 const char *stdin_path, 703 const char *stdout_path, 704 const char *stderr_path, 705 const char *working_directory, 706 uint32_t launch_flags, // See LaunchFlags 707 bool stop_at_entry, 708 lldb::SBError& error 709 ) 710 { 711 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 712 713 SBProcess sb_process; 714 ProcessSP process_sp; 715 TargetSP target_sp(GetSP()); 716 717 if (log) 718 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", 719 static_cast<void*>(target_sp.get()), 720 static_cast<void*>(argv), static_cast<void*>(envp), 721 stdin_path ? stdin_path : "NULL", 722 stdout_path ? stdout_path : "NULL", 723 stderr_path ? stderr_path : "NULL", 724 working_directory ? working_directory : "NULL", 725 launch_flags, stop_at_entry, 726 static_cast<void*>(error.get())); 727 728 if (target_sp) 729 { 730 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 731 732 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) 733 launch_flags |= eLaunchFlagDisableASLR; 734 735 StateType state = eStateInvalid; 736 process_sp = target_sp->GetProcessSP(); 737 if (process_sp) 738 { 739 state = process_sp->GetState(); 740 741 if (process_sp->IsAlive() && state != eStateConnected) 742 { 743 if (state == eStateAttaching) 744 error.SetErrorString ("process attach is in progress"); 745 else 746 error.SetErrorString ("a process is already being debugged"); 747 return sb_process; 748 } 749 } 750 751 if (state == eStateConnected) 752 { 753 // If we are already connected, then we have already specified the 754 // listener, so if a valid listener is supplied, we need to error out 755 // to let the client know. 756 if (listener.IsValid()) 757 { 758 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 759 return sb_process; 760 } 761 } 762 763 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) 764 launch_flags |= eLaunchFlagDisableSTDIO; 765 766 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); 767 768 Module *exe_module = target_sp->GetExecutableModulePointer(); 769 if (exe_module) 770 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 771 if (argv) 772 launch_info.GetArguments().AppendArguments (argv); 773 if (envp) 774 launch_info.GetEnvironmentEntries ().SetArguments (envp); 775 776 if (listener.IsValid()) 777 launch_info.SetListener(listener.GetSP()); 778 779 error.SetError (target_sp->Launch(launch_info, NULL)); 780 781 sb_process.SetSP(target_sp->GetProcessSP()); 782 } 783 else 784 { 785 error.SetErrorString ("SBTarget is invalid"); 786 } 787 788 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 789 if (log) 790 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", 791 static_cast<void*>(target_sp.get()), 792 static_cast<void*>(sb_process.GetSP().get())); 793 794 return sb_process; 795 } 796 797 SBProcess 798 SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) 799 { 800 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 801 802 SBProcess sb_process; 803 TargetSP target_sp(GetSP()); 804 805 if (log) 806 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", 807 static_cast<void*>(target_sp.get())); 808 809 if (target_sp) 810 { 811 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 812 StateType state = eStateInvalid; 813 { 814 ProcessSP process_sp = target_sp->GetProcessSP(); 815 if (process_sp) 816 { 817 state = process_sp->GetState(); 818 819 if (process_sp->IsAlive() && state != eStateConnected) 820 { 821 if (state == eStateAttaching) 822 error.SetErrorString ("process attach is in progress"); 823 else 824 error.SetErrorString ("a process is already being debugged"); 825 return sb_process; 826 } 827 } 828 } 829 830 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref(); 831 832 if (!launch_info.GetExecutableFile()) 833 { 834 Module *exe_module = target_sp->GetExecutableModulePointer(); 835 if (exe_module) 836 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 837 } 838 839 const ArchSpec &arch_spec = target_sp->GetArchitecture(); 840 if (arch_spec.IsValid()) 841 launch_info.GetArchitecture () = arch_spec; 842 843 error.SetError (target_sp->Launch (launch_info, NULL)); 844 sb_process.SetSP(target_sp->GetProcessSP()); 845 } 846 else 847 { 848 error.SetErrorString ("SBTarget is invalid"); 849 } 850 851 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 852 if (log) 853 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", 854 static_cast<void*>(target_sp.get()), 855 static_cast<void*>(sb_process.GetSP().get())); 856 857 return sb_process; 858 } 859 860 lldb::SBProcess 861 SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error) 862 { 863 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 864 865 SBProcess sb_process; 866 ProcessSP process_sp; 867 TargetSP target_sp(GetSP()); 868 869 if (log) 870 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", 871 static_cast<void*>(target_sp.get())); 872 873 if (target_sp) 874 { 875 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 876 877 StateType state = eStateInvalid; 878 process_sp = target_sp->GetProcessSP(); 879 if (process_sp) 880 { 881 state = process_sp->GetState(); 882 883 if (process_sp->IsAlive() && state != eStateConnected) 884 { 885 if (state == eStateAttaching) 886 error.SetErrorString ("process attach is in progress"); 887 else 888 error.SetErrorString ("a process is already being debugged"); 889 if (log) 890 log->Printf ("SBTarget(%p)::Attach (...) => error %s", 891 static_cast<void*>(target_sp.get()), 892 error.GetCString()); 893 return sb_process; 894 } 895 } 896 897 if (state != eStateConnected) 898 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 899 900 if (process_sp) 901 { 902 ProcessAttachInfo &attach_info = sb_attach_info.ref(); 903 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) 904 { 905 PlatformSP platform_sp = target_sp->GetPlatform(); 906 // See if we can pre-verify if a process exists or not 907 if (platform_sp && platform_sp->IsConnected()) 908 { 909 lldb::pid_t attach_pid = attach_info.GetProcessID(); 910 ProcessInstanceInfo instance_info; 911 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) 912 { 913 attach_info.SetUserID(instance_info.GetEffectiveUserID()); 914 } 915 else 916 { 917 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid); 918 if (log) 919 { 920 log->Printf ("SBTarget(%p)::Attach (...) => error %s", 921 static_cast<void*>(target_sp.get()), error.GetCString()); 922 } 923 return sb_process; 924 } 925 } 926 } 927 error.SetError (process_sp->Attach (attach_info)); 928 if (error.Success()) 929 { 930 sb_process.SetSP (process_sp); 931 // If we are doing synchronous mode, then wait for the 932 // process to stop! 933 if (target_sp->GetDebugger().GetAsyncExecution () == false) 934 process_sp->WaitForProcessToStop (NULL); 935 } 936 } 937 else 938 { 939 error.SetErrorString ("unable to create lldb_private::Process"); 940 } 941 } 942 else 943 { 944 error.SetErrorString ("SBTarget is invalid"); 945 } 946 947 if (log) 948 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)", 949 static_cast<void*>(target_sp.get()), 950 static_cast<void*>(process_sp.get())); 951 952 return sb_process; 953 } 954 955 956 #if defined(__APPLE__) 957 958 lldb::SBProcess 959 SBTarget::AttachToProcessWithID (SBListener &listener, 960 ::pid_t pid, 961 lldb::SBError& error) 962 { 963 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); 964 } 965 966 #endif // #if defined(__APPLE__) 967 968 lldb::SBProcess 969 SBTarget::AttachToProcessWithID 970 ( 971 SBListener &listener, 972 lldb::pid_t pid,// The process ID to attach to 973 SBError& error // An error explaining what went wrong if attach fails 974 ) 975 { 976 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 977 978 SBProcess sb_process; 979 ProcessSP process_sp; 980 TargetSP target_sp(GetSP()); 981 982 if (log) 983 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", 984 static_cast<void*>(target_sp.get()), pid); 985 986 if (target_sp) 987 { 988 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 989 990 StateType state = eStateInvalid; 991 process_sp = target_sp->GetProcessSP(); 992 if (process_sp) 993 { 994 state = process_sp->GetState(); 995 996 if (process_sp->IsAlive() && state != eStateConnected) 997 { 998 if (state == eStateAttaching) 999 error.SetErrorString ("process attach is in progress"); 1000 else 1001 error.SetErrorString ("a process is already being debugged"); 1002 return sb_process; 1003 } 1004 } 1005 1006 if (state == eStateConnected) 1007 { 1008 // If we are already connected, then we have already specified the 1009 // listener, so if a valid listener is supplied, we need to error out 1010 // to let the client know. 1011 if (listener.IsValid()) 1012 { 1013 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 1014 return sb_process; 1015 } 1016 } 1017 else 1018 { 1019 if (listener.IsValid()) 1020 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); 1021 else 1022 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 1023 } 1024 if (process_sp) 1025 { 1026 sb_process.SetSP (process_sp); 1027 1028 ProcessAttachInfo attach_info; 1029 attach_info.SetProcessID (pid); 1030 1031 PlatformSP platform_sp = target_sp->GetPlatform(); 1032 ProcessInstanceInfo instance_info; 1033 if (platform_sp->GetProcessInfo(pid, instance_info)) 1034 { 1035 attach_info.SetUserID(instance_info.GetEffectiveUserID()); 1036 } 1037 error.SetError (process_sp->Attach (attach_info)); 1038 if (error.Success()) 1039 { 1040 // If we are doing synchronous mode, then wait for the 1041 // process to stop! 1042 if (target_sp->GetDebugger().GetAsyncExecution () == false) 1043 process_sp->WaitForProcessToStop (NULL); 1044 } 1045 } 1046 else 1047 { 1048 error.SetErrorString ("unable to create lldb_private::Process"); 1049 } 1050 } 1051 else 1052 { 1053 error.SetErrorString ("SBTarget is invalid"); 1054 } 1055 1056 if (log) 1057 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)", 1058 static_cast<void*>(target_sp.get()), 1059 static_cast<void*>(process_sp.get())); 1060 return sb_process; 1061 } 1062 1063 lldb::SBProcess 1064 SBTarget::AttachToProcessWithName 1065 ( 1066 SBListener &listener, 1067 const char *name, // basename of process to attach to 1068 bool wait_for, // if true wait for a new instance of "name" to be launched 1069 SBError& error // An error explaining what went wrong if attach fails 1070 ) 1071 { 1072 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1073 1074 SBProcess sb_process; 1075 ProcessSP process_sp; 1076 TargetSP target_sp(GetSP()); 1077 1078 if (log) 1079 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", 1080 static_cast<void*>(target_sp.get()), name, 1081 wait_for ? "true" : "false"); 1082 1083 if (name && target_sp) 1084 { 1085 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1086 1087 StateType state = eStateInvalid; 1088 process_sp = target_sp->GetProcessSP(); 1089 if (process_sp) 1090 { 1091 state = process_sp->GetState(); 1092 1093 if (process_sp->IsAlive() && state != eStateConnected) 1094 { 1095 if (state == eStateAttaching) 1096 error.SetErrorString ("process attach is in progress"); 1097 else 1098 error.SetErrorString ("a process is already being debugged"); 1099 return sb_process; 1100 } 1101 } 1102 1103 if (state == eStateConnected) 1104 { 1105 // If we are already connected, then we have already specified the 1106 // listener, so if a valid listener is supplied, we need to error out 1107 // to let the client know. 1108 if (listener.IsValid()) 1109 { 1110 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 1111 return sb_process; 1112 } 1113 } 1114 else 1115 { 1116 if (listener.IsValid()) 1117 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); 1118 else 1119 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 1120 } 1121 1122 if (process_sp) 1123 { 1124 sb_process.SetSP (process_sp); 1125 ProcessAttachInfo attach_info; 1126 attach_info.GetExecutableFile().SetFile(name, false); 1127 attach_info.SetWaitForLaunch(wait_for); 1128 error.SetError (process_sp->Attach (attach_info)); 1129 if (error.Success()) 1130 { 1131 // If we are doing synchronous mode, then wait for the 1132 // process to stop! 1133 if (target_sp->GetDebugger().GetAsyncExecution () == false) 1134 process_sp->WaitForProcessToStop (NULL); 1135 } 1136 } 1137 else 1138 { 1139 error.SetErrorString ("unable to create lldb_private::Process"); 1140 } 1141 } 1142 else 1143 { 1144 error.SetErrorString ("SBTarget is invalid"); 1145 } 1146 1147 if (log) 1148 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)", 1149 static_cast<void*>(target_sp.get()), 1150 static_cast<void*>(process_sp.get())); 1151 return sb_process; 1152 } 1153 1154 lldb::SBProcess 1155 SBTarget::ConnectRemote 1156 ( 1157 SBListener &listener, 1158 const char *url, 1159 const char *plugin_name, 1160 SBError& error 1161 ) 1162 { 1163 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1164 1165 SBProcess sb_process; 1166 ProcessSP process_sp; 1167 TargetSP target_sp(GetSP()); 1168 1169 if (log) 1170 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", 1171 static_cast<void*>(target_sp.get()), url, plugin_name); 1172 1173 if (target_sp) 1174 { 1175 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1176 if (listener.IsValid()) 1177 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); 1178 else 1179 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); 1180 1181 if (process_sp) 1182 { 1183 sb_process.SetSP (process_sp); 1184 error.SetError (process_sp->ConnectRemote (NULL, url)); 1185 } 1186 else 1187 { 1188 error.SetErrorString ("unable to create lldb_private::Process"); 1189 } 1190 } 1191 else 1192 { 1193 error.SetErrorString ("SBTarget is invalid"); 1194 } 1195 1196 if (log) 1197 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)", 1198 static_cast<void*>(target_sp.get()), 1199 static_cast<void*>(process_sp.get())); 1200 return sb_process; 1201 } 1202 1203 SBFileSpec 1204 SBTarget::GetExecutable () 1205 { 1206 1207 SBFileSpec exe_file_spec; 1208 TargetSP target_sp(GetSP()); 1209 if (target_sp) 1210 { 1211 Module *exe_module = target_sp->GetExecutableModulePointer(); 1212 if (exe_module) 1213 exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); 1214 } 1215 1216 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1217 if (log) 1218 { 1219 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", 1220 static_cast<void*>(target_sp.get()), 1221 static_cast<const void*>(exe_file_spec.get())); 1222 } 1223 1224 return exe_file_spec; 1225 } 1226 1227 bool 1228 SBTarget::operator == (const SBTarget &rhs) const 1229 { 1230 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 1231 } 1232 1233 bool 1234 SBTarget::operator != (const SBTarget &rhs) const 1235 { 1236 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 1237 } 1238 1239 lldb::TargetSP 1240 SBTarget::GetSP () const 1241 { 1242 return m_opaque_sp; 1243 } 1244 1245 void 1246 SBTarget::SetSP (const lldb::TargetSP& target_sp) 1247 { 1248 m_opaque_sp = target_sp; 1249 } 1250 1251 lldb::SBAddress 1252 SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) 1253 { 1254 lldb::SBAddress sb_addr; 1255 Address &addr = sb_addr.ref(); 1256 TargetSP target_sp(GetSP()); 1257 if (target_sp) 1258 { 1259 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1260 if (target_sp->ResolveLoadAddress (vm_addr, addr)) 1261 return sb_addr; 1262 } 1263 1264 // We have a load address that isn't in a section, just return an address 1265 // with the offset filled in (the address) and the section set to NULL 1266 addr.SetRawAddress(vm_addr); 1267 return sb_addr; 1268 } 1269 1270 lldb::SBAddress 1271 SBTarget::ResolveFileAddress (lldb::addr_t file_addr) 1272 { 1273 lldb::SBAddress sb_addr; 1274 Address &addr = sb_addr.ref(); 1275 TargetSP target_sp(GetSP()); 1276 if (target_sp) 1277 { 1278 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1279 if (target_sp->ResolveFileAddress (file_addr, addr)) 1280 return sb_addr; 1281 } 1282 1283 addr.SetRawAddress(file_addr); 1284 return sb_addr; 1285 } 1286 1287 lldb::SBAddress 1288 SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr) 1289 { 1290 lldb::SBAddress sb_addr; 1291 Address &addr = sb_addr.ref(); 1292 TargetSP target_sp(GetSP()); 1293 if (target_sp) 1294 { 1295 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1296 if (target_sp->ResolveLoadAddress (vm_addr, addr)) 1297 return sb_addr; 1298 } 1299 1300 // We have a load address that isn't in a section, just return an address 1301 // with the offset filled in (the address) and the section set to NULL 1302 addr.SetRawAddress(vm_addr); 1303 return sb_addr; 1304 } 1305 1306 SBSymbolContext 1307 SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, 1308 uint32_t resolve_scope) 1309 { 1310 SBSymbolContext sc; 1311 if (addr.IsValid()) 1312 { 1313 TargetSP target_sp(GetSP()); 1314 if (target_sp) 1315 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); 1316 } 1317 return sc; 1318 } 1319 1320 size_t 1321 SBTarget::ReadMemory (const SBAddress addr, 1322 void *buf, 1323 size_t size, 1324 lldb::SBError &error) 1325 { 1326 SBError sb_error; 1327 size_t bytes_read = 0; 1328 TargetSP target_sp(GetSP()); 1329 if (target_sp) 1330 { 1331 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1332 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref()); 1333 } 1334 else 1335 { 1336 sb_error.SetErrorString("invalid target"); 1337 } 1338 1339 return bytes_read; 1340 } 1341 1342 SBBreakpoint 1343 SBTarget::BreakpointCreateByLocation (const char *file, 1344 uint32_t line) 1345 { 1346 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); 1347 } 1348 1349 SBBreakpoint 1350 SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, 1351 uint32_t line) 1352 { 1353 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1354 1355 SBBreakpoint sb_bp; 1356 TargetSP target_sp(GetSP()); 1357 if (target_sp && line != 0) 1358 { 1359 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1360 1361 const LazyBool check_inlines = eLazyBoolCalculate; 1362 const LazyBool skip_prologue = eLazyBoolCalculate; 1363 const bool internal = false; 1364 const bool hardware = false; 1365 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware); 1366 } 1367 1368 if (log) 1369 { 1370 SBStream sstr; 1371 sb_bp.GetDescription (sstr); 1372 char path[PATH_MAX]; 1373 sb_file_spec->GetPath (path, sizeof(path)); 1374 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", 1375 static_cast<void*>(target_sp.get()), path, line, 1376 static_cast<void*>(sb_bp.get()), sstr.GetData()); 1377 } 1378 1379 return sb_bp; 1380 } 1381 1382 SBBreakpoint 1383 SBTarget::BreakpointCreateByName (const char *symbol_name, 1384 const char *module_name) 1385 { 1386 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1387 1388 SBBreakpoint sb_bp; 1389 TargetSP target_sp(GetSP()); 1390 if (target_sp.get()) 1391 { 1392 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1393 1394 const bool internal = false; 1395 const bool hardware = false; 1396 const LazyBool skip_prologue = eLazyBoolCalculate; 1397 if (module_name && module_name[0]) 1398 { 1399 FileSpecList module_spec_list; 1400 module_spec_list.Append (FileSpec (module_name, false)); 1401 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware); 1402 } 1403 else 1404 { 1405 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware); 1406 } 1407 } 1408 1409 if (log) 1410 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", 1411 static_cast<void*>(target_sp.get()), symbol_name, 1412 module_name, static_cast<void*>(sb_bp.get())); 1413 1414 return sb_bp; 1415 } 1416 1417 lldb::SBBreakpoint 1418 SBTarget::BreakpointCreateByName (const char *symbol_name, 1419 const SBFileSpecList &module_list, 1420 const SBFileSpecList &comp_unit_list) 1421 { 1422 uint32_t name_type_mask = eFunctionNameTypeAuto; 1423 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); 1424 } 1425 1426 lldb::SBBreakpoint 1427 SBTarget::BreakpointCreateByName (const char *symbol_name, 1428 uint32_t name_type_mask, 1429 const SBFileSpecList &module_list, 1430 const SBFileSpecList &comp_unit_list) 1431 { 1432 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1433 1434 SBBreakpoint sb_bp; 1435 TargetSP target_sp(GetSP()); 1436 if (target_sp && symbol_name && symbol_name[0]) 1437 { 1438 const bool internal = false; 1439 const bool hardware = false; 1440 const LazyBool skip_prologue = eLazyBoolCalculate; 1441 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1442 *sb_bp = target_sp->CreateBreakpoint (module_list.get(), 1443 comp_unit_list.get(), 1444 symbol_name, 1445 name_type_mask, 1446 skip_prologue, 1447 internal, 1448 hardware); 1449 } 1450 1451 if (log) 1452 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", 1453 static_cast<void*>(target_sp.get()), symbol_name, 1454 name_type_mask, static_cast<void*>(sb_bp.get())); 1455 1456 return sb_bp; 1457 } 1458 1459 lldb::SBBreakpoint 1460 SBTarget::BreakpointCreateByNames (const char *symbol_names[], 1461 uint32_t num_names, 1462 uint32_t name_type_mask, 1463 const SBFileSpecList &module_list, 1464 const SBFileSpecList &comp_unit_list) 1465 { 1466 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1467 1468 SBBreakpoint sb_bp; 1469 TargetSP target_sp(GetSP()); 1470 if (target_sp && num_names > 0) 1471 { 1472 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1473 const bool internal = false; 1474 const bool hardware = false; 1475 const LazyBool skip_prologue = eLazyBoolCalculate; 1476 *sb_bp = target_sp->CreateBreakpoint (module_list.get(), 1477 comp_unit_list.get(), 1478 symbol_names, 1479 num_names, 1480 name_type_mask, 1481 skip_prologue, 1482 internal, 1483 hardware); 1484 } 1485 1486 if (log) 1487 { 1488 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", 1489 static_cast<void*>(target_sp.get())); 1490 for (uint32_t i = 0 ; i < num_names; i++) 1491 { 1492 char sep; 1493 if (i < num_names - 1) 1494 sep = ','; 1495 else 1496 sep = '}'; 1497 if (symbol_names[i] != NULL) 1498 log->Printf ("\"%s\"%c ", symbol_names[i], sep); 1499 else 1500 log->Printf ("\"<NULL>\"%c ", sep); 1501 } 1502 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, 1503 static_cast<void*>(sb_bp.get())); 1504 } 1505 1506 return sb_bp; 1507 } 1508 1509 SBBreakpoint 1510 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 1511 const char *module_name) 1512 { 1513 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1514 1515 SBBreakpoint sb_bp; 1516 TargetSP target_sp(GetSP()); 1517 if (target_sp && symbol_name_regex && symbol_name_regex[0]) 1518 { 1519 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1520 RegularExpression regexp(symbol_name_regex); 1521 const bool internal = false; 1522 const bool hardware = false; 1523 const LazyBool skip_prologue = eLazyBoolCalculate; 1524 1525 if (module_name && module_name[0]) 1526 { 1527 FileSpecList module_spec_list; 1528 module_spec_list.Append (FileSpec (module_name, false)); 1529 1530 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware); 1531 } 1532 else 1533 { 1534 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware); 1535 } 1536 } 1537 1538 if (log) 1539 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", 1540 static_cast<void*>(target_sp.get()), symbol_name_regex, 1541 module_name, static_cast<void*>(sb_bp.get())); 1542 1543 return sb_bp; 1544 } 1545 1546 lldb::SBBreakpoint 1547 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 1548 const SBFileSpecList &module_list, 1549 const SBFileSpecList &comp_unit_list) 1550 { 1551 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1552 1553 SBBreakpoint sb_bp; 1554 TargetSP target_sp(GetSP()); 1555 if (target_sp && symbol_name_regex && symbol_name_regex[0]) 1556 { 1557 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1558 RegularExpression regexp(symbol_name_regex); 1559 const bool internal = false; 1560 const bool hardware = false; 1561 const LazyBool skip_prologue = eLazyBoolCalculate; 1562 1563 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware); 1564 } 1565 1566 if (log) 1567 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", 1568 static_cast<void*>(target_sp.get()), symbol_name_regex, 1569 static_cast<void*>(sb_bp.get())); 1570 1571 return sb_bp; 1572 } 1573 1574 SBBreakpoint 1575 SBTarget::BreakpointCreateByAddress (addr_t address) 1576 { 1577 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1578 1579 SBBreakpoint sb_bp; 1580 TargetSP target_sp(GetSP()); 1581 if (target_sp) 1582 { 1583 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1584 const bool hardware = false; 1585 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware); 1586 } 1587 1588 if (log) 1589 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", 1590 static_cast<void*>(target_sp.get()), 1591 static_cast<uint64_t>(address), 1592 static_cast<void*>(sb_bp.get())); 1593 1594 return sb_bp; 1595 } 1596 1597 lldb::SBBreakpoint 1598 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, 1599 const lldb::SBFileSpec &source_file, 1600 const char *module_name) 1601 { 1602 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1603 1604 SBBreakpoint sb_bp; 1605 TargetSP target_sp(GetSP()); 1606 if (target_sp && source_regex && source_regex[0]) 1607 { 1608 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1609 RegularExpression regexp(source_regex); 1610 FileSpecList source_file_spec_list; 1611 const bool hardware = false; 1612 source_file_spec_list.Append (source_file.ref()); 1613 1614 if (module_name && module_name[0]) 1615 { 1616 FileSpecList module_spec_list; 1617 module_spec_list.Append (FileSpec (module_name, false)); 1618 1619 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware); 1620 } 1621 else 1622 { 1623 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware); 1624 } 1625 } 1626 1627 if (log) 1628 { 1629 char path[PATH_MAX]; 1630 source_file->GetPath (path, sizeof(path)); 1631 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", 1632 static_cast<void*>(target_sp.get()), source_regex, path, 1633 module_name, static_cast<void*>(sb_bp.get())); 1634 } 1635 1636 return sb_bp; 1637 } 1638 1639 lldb::SBBreakpoint 1640 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, 1641 const SBFileSpecList &module_list, 1642 const lldb::SBFileSpecList &source_file_list) 1643 { 1644 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1645 1646 SBBreakpoint sb_bp; 1647 TargetSP target_sp(GetSP()); 1648 if (target_sp && source_regex && source_regex[0]) 1649 { 1650 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1651 const bool hardware = false; 1652 RegularExpression regexp(source_regex); 1653 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware); 1654 } 1655 1656 if (log) 1657 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", 1658 static_cast<void*>(target_sp.get()), source_regex, 1659 static_cast<void*>(sb_bp.get())); 1660 1661 return sb_bp; 1662 } 1663 1664 lldb::SBBreakpoint 1665 SBTarget::BreakpointCreateForException (lldb::LanguageType language, 1666 bool catch_bp, 1667 bool throw_bp) 1668 { 1669 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1670 1671 SBBreakpoint sb_bp; 1672 TargetSP target_sp(GetSP()); 1673 if (target_sp) 1674 { 1675 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1676 const bool hardware = false; 1677 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware); 1678 } 1679 1680 if (log) 1681 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)", 1682 static_cast<void*>(target_sp.get()), 1683 LanguageRuntime::GetNameForLanguageType(language), 1684 catch_bp ? "on" : "off", throw_bp ? "on" : "off", 1685 static_cast<void*>(sb_bp.get())); 1686 1687 return sb_bp; 1688 } 1689 1690 uint32_t 1691 SBTarget::GetNumBreakpoints () const 1692 { 1693 TargetSP target_sp(GetSP()); 1694 if (target_sp) 1695 { 1696 // The breakpoint list is thread safe, no need to lock 1697 return target_sp->GetBreakpointList().GetSize(); 1698 } 1699 return 0; 1700 } 1701 1702 SBBreakpoint 1703 SBTarget::GetBreakpointAtIndex (uint32_t idx) const 1704 { 1705 SBBreakpoint sb_breakpoint; 1706 TargetSP target_sp(GetSP()); 1707 if (target_sp) 1708 { 1709 // The breakpoint list is thread safe, no need to lock 1710 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); 1711 } 1712 return sb_breakpoint; 1713 } 1714 1715 bool 1716 SBTarget::BreakpointDelete (break_id_t bp_id) 1717 { 1718 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1719 1720 bool result = false; 1721 TargetSP target_sp(GetSP()); 1722 if (target_sp) 1723 { 1724 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1725 result = target_sp->RemoveBreakpointByID (bp_id); 1726 } 1727 1728 if (log) 1729 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", 1730 static_cast<void*>(target_sp.get()), 1731 static_cast<uint32_t>(bp_id), result); 1732 1733 return result; 1734 } 1735 1736 SBBreakpoint 1737 SBTarget::FindBreakpointByID (break_id_t bp_id) 1738 { 1739 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1740 1741 SBBreakpoint sb_breakpoint; 1742 TargetSP target_sp(GetSP()); 1743 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) 1744 { 1745 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1746 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); 1747 } 1748 1749 if (log) 1750 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", 1751 static_cast<void*>(target_sp.get()), 1752 static_cast<uint32_t>(bp_id), 1753 static_cast<void*>(sb_breakpoint.get())); 1754 1755 return sb_breakpoint; 1756 } 1757 1758 bool 1759 SBTarget::EnableAllBreakpoints () 1760 { 1761 TargetSP target_sp(GetSP()); 1762 if (target_sp) 1763 { 1764 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1765 target_sp->EnableAllBreakpoints (); 1766 return true; 1767 } 1768 return false; 1769 } 1770 1771 bool 1772 SBTarget::DisableAllBreakpoints () 1773 { 1774 TargetSP target_sp(GetSP()); 1775 if (target_sp) 1776 { 1777 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1778 target_sp->DisableAllBreakpoints (); 1779 return true; 1780 } 1781 return false; 1782 } 1783 1784 bool 1785 SBTarget::DeleteAllBreakpoints () 1786 { 1787 TargetSP target_sp(GetSP()); 1788 if (target_sp) 1789 { 1790 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1791 target_sp->RemoveAllBreakpoints (); 1792 return true; 1793 } 1794 return false; 1795 } 1796 1797 uint32_t 1798 SBTarget::GetNumWatchpoints () const 1799 { 1800 TargetSP target_sp(GetSP()); 1801 if (target_sp) 1802 { 1803 // The watchpoint list is thread safe, no need to lock 1804 return target_sp->GetWatchpointList().GetSize(); 1805 } 1806 return 0; 1807 } 1808 1809 SBWatchpoint 1810 SBTarget::GetWatchpointAtIndex (uint32_t idx) const 1811 { 1812 SBWatchpoint sb_watchpoint; 1813 TargetSP target_sp(GetSP()); 1814 if (target_sp) 1815 { 1816 // The watchpoint list is thread safe, no need to lock 1817 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); 1818 } 1819 return sb_watchpoint; 1820 } 1821 1822 bool 1823 SBTarget::DeleteWatchpoint (watch_id_t wp_id) 1824 { 1825 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1826 1827 bool result = false; 1828 TargetSP target_sp(GetSP()); 1829 if (target_sp) 1830 { 1831 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1832 Mutex::Locker locker; 1833 target_sp->GetWatchpointList().GetListMutex(locker); 1834 result = target_sp->RemoveWatchpointByID (wp_id); 1835 } 1836 1837 if (log) 1838 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", 1839 static_cast<void*>(target_sp.get()), 1840 static_cast<uint32_t>(wp_id), result); 1841 1842 return result; 1843 } 1844 1845 SBWatchpoint 1846 SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) 1847 { 1848 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1849 1850 SBWatchpoint sb_watchpoint; 1851 lldb::WatchpointSP watchpoint_sp; 1852 TargetSP target_sp(GetSP()); 1853 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) 1854 { 1855 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1856 Mutex::Locker locker; 1857 target_sp->GetWatchpointList().GetListMutex(locker); 1858 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); 1859 sb_watchpoint.SetSP (watchpoint_sp); 1860 } 1861 1862 if (log) 1863 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", 1864 static_cast<void*>(target_sp.get()), 1865 static_cast<uint32_t>(wp_id), 1866 static_cast<void*>(watchpoint_sp.get())); 1867 1868 return sb_watchpoint; 1869 } 1870 1871 lldb::SBWatchpoint 1872 SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error) 1873 { 1874 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1875 1876 SBWatchpoint sb_watchpoint; 1877 lldb::WatchpointSP watchpoint_sp; 1878 TargetSP target_sp(GetSP()); 1879 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) 1880 { 1881 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1882 uint32_t watch_type = 0; 1883 if (read) 1884 watch_type |= LLDB_WATCH_TYPE_READ; 1885 if (write) 1886 watch_type |= LLDB_WATCH_TYPE_WRITE; 1887 if (watch_type == 0) 1888 { 1889 error.SetErrorString("Can't create a watchpoint that is neither read nor write."); 1890 return sb_watchpoint; 1891 } 1892 1893 // Target::CreateWatchpoint() is thread safe. 1894 Error cw_error; 1895 // This API doesn't take in a type, so we can't figure out what it is. 1896 ClangASTType *type = NULL; 1897 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); 1898 error.SetError(cw_error); 1899 sb_watchpoint.SetSP (watchpoint_sp); 1900 } 1901 1902 if (log) 1903 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)", 1904 static_cast<void*>(target_sp.get()), addr, 1905 static_cast<uint32_t>(size), 1906 static_cast<void*>(watchpoint_sp.get())); 1907 1908 return sb_watchpoint; 1909 } 1910 1911 bool 1912 SBTarget::EnableAllWatchpoints () 1913 { 1914 TargetSP target_sp(GetSP()); 1915 if (target_sp) 1916 { 1917 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1918 Mutex::Locker locker; 1919 target_sp->GetWatchpointList().GetListMutex(locker); 1920 target_sp->EnableAllWatchpoints (); 1921 return true; 1922 } 1923 return false; 1924 } 1925 1926 bool 1927 SBTarget::DisableAllWatchpoints () 1928 { 1929 TargetSP target_sp(GetSP()); 1930 if (target_sp) 1931 { 1932 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1933 Mutex::Locker locker; 1934 target_sp->GetWatchpointList().GetListMutex(locker); 1935 target_sp->DisableAllWatchpoints (); 1936 return true; 1937 } 1938 return false; 1939 } 1940 1941 SBValue 1942 SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type) 1943 { 1944 SBValue sb_value; 1945 lldb::ValueObjectSP new_value_sp; 1946 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) 1947 { 1948 lldb::addr_t address(addr.GetLoadAddress(*this)); 1949 lldb::TypeImplSP type_impl_sp (type.GetSP()); 1950 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ()); 1951 if (pointer_ast_type) 1952 { 1953 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); 1954 1955 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); 1956 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 1957 pointer_ast_type, 1958 ConstString(name), 1959 buffer, 1960 exe_ctx.GetByteOrder(), 1961 exe_ctx.GetAddressByteSize())); 1962 1963 if (ptr_result_valobj_sp) 1964 { 1965 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); 1966 Error err; 1967 new_value_sp = ptr_result_valobj_sp->Dereference(err); 1968 if (new_value_sp) 1969 new_value_sp->SetName(ConstString(name)); 1970 } 1971 } 1972 } 1973 sb_value.SetSP(new_value_sp); 1974 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1975 if (log) 1976 { 1977 if (new_value_sp) 1978 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", 1979 static_cast<void*>(m_opaque_sp.get()), 1980 new_value_sp->GetName().AsCString()); 1981 else 1982 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", 1983 static_cast<void*>(m_opaque_sp.get())); 1984 } 1985 return sb_value; 1986 } 1987 1988 bool 1989 SBTarget::DeleteAllWatchpoints () 1990 { 1991 TargetSP target_sp(GetSP()); 1992 if (target_sp) 1993 { 1994 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1995 Mutex::Locker locker; 1996 target_sp->GetWatchpointList().GetListMutex(locker); 1997 target_sp->RemoveAllWatchpoints (); 1998 return true; 1999 } 2000 return false; 2001 } 2002 2003 2004 lldb::SBModule 2005 SBTarget::AddModule (const char *path, 2006 const char *triple, 2007 const char *uuid_cstr) 2008 { 2009 return AddModule (path, triple, uuid_cstr, NULL); 2010 } 2011 2012 lldb::SBModule 2013 SBTarget::AddModule (const char *path, 2014 const char *triple, 2015 const char *uuid_cstr, 2016 const char *symfile) 2017 { 2018 lldb::SBModule sb_module; 2019 TargetSP target_sp(GetSP()); 2020 if (target_sp) 2021 { 2022 ModuleSpec module_spec; 2023 if (path) 2024 module_spec.GetFileSpec().SetFile(path, false); 2025 2026 if (uuid_cstr) 2027 module_spec.GetUUID().SetFromCString(uuid_cstr); 2028 2029 if (triple) 2030 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get()); 2031 else 2032 module_spec.GetArchitecture() = target_sp->GetArchitecture(); 2033 2034 if (symfile) 2035 module_spec.GetSymbolFileSpec ().SetFile(symfile, false); 2036 2037 sb_module.SetSP(target_sp->GetSharedModule (module_spec)); 2038 } 2039 return sb_module; 2040 } 2041 2042 lldb::SBModule 2043 SBTarget::AddModule (const SBModuleSpec &module_spec) 2044 { 2045 lldb::SBModule sb_module; 2046 TargetSP target_sp(GetSP()); 2047 if (target_sp) 2048 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap)); 2049 return sb_module; 2050 } 2051 2052 bool 2053 SBTarget::AddModule (lldb::SBModule &module) 2054 { 2055 TargetSP target_sp(GetSP()); 2056 if (target_sp) 2057 { 2058 target_sp->GetImages().AppendIfNeeded (module.GetSP()); 2059 return true; 2060 } 2061 return false; 2062 } 2063 2064 uint32_t 2065 SBTarget::GetNumModules () const 2066 { 2067 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2068 2069 uint32_t num = 0; 2070 TargetSP target_sp(GetSP()); 2071 if (target_sp) 2072 { 2073 // The module list is thread safe, no need to lock 2074 num = target_sp->GetImages().GetSize(); 2075 } 2076 2077 if (log) 2078 log->Printf ("SBTarget(%p)::GetNumModules () => %d", 2079 static_cast<void*>(target_sp.get()), num); 2080 2081 return num; 2082 } 2083 2084 void 2085 SBTarget::Clear () 2086 { 2087 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2088 2089 if (log) 2090 log->Printf ("SBTarget(%p)::Clear ()", 2091 static_cast<void*>(m_opaque_sp.get())); 2092 2093 m_opaque_sp.reset(); 2094 } 2095 2096 2097 SBModule 2098 SBTarget::FindModule (const SBFileSpec &sb_file_spec) 2099 { 2100 SBModule sb_module; 2101 TargetSP target_sp(GetSP()); 2102 if (target_sp && sb_file_spec.IsValid()) 2103 { 2104 ModuleSpec module_spec(*sb_file_spec); 2105 // The module list is thread safe, no need to lock 2106 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec)); 2107 } 2108 return sb_module; 2109 } 2110 2111 lldb::ByteOrder 2112 SBTarget::GetByteOrder () 2113 { 2114 TargetSP target_sp(GetSP()); 2115 if (target_sp) 2116 return target_sp->GetArchitecture().GetByteOrder(); 2117 return eByteOrderInvalid; 2118 } 2119 2120 const char * 2121 SBTarget::GetTriple () 2122 { 2123 TargetSP target_sp(GetSP()); 2124 if (target_sp) 2125 { 2126 std::string triple (target_sp->GetArchitecture().GetTriple().str()); 2127 // Unique the string so we don't run into ownership issues since 2128 // the const strings put the string into the string pool once and 2129 // the strings never comes out 2130 ConstString const_triple (triple.c_str()); 2131 return const_triple.GetCString(); 2132 } 2133 return NULL; 2134 } 2135 2136 uint32_t 2137 SBTarget::GetDataByteSize () 2138 { 2139 TargetSP target_sp(GetSP()); 2140 if (target_sp) 2141 { 2142 return target_sp->GetArchitecture().GetDataByteSize() ; 2143 } 2144 return 0; 2145 } 2146 2147 uint32_t 2148 SBTarget::GetCodeByteSize () 2149 { 2150 TargetSP target_sp(GetSP()); 2151 if (target_sp) 2152 { 2153 return target_sp->GetArchitecture().GetCodeByteSize() ; 2154 } 2155 return 0; 2156 } 2157 2158 uint32_t 2159 SBTarget::GetAddressByteSize() 2160 { 2161 TargetSP target_sp(GetSP()); 2162 if (target_sp) 2163 return target_sp->GetArchitecture().GetAddressByteSize(); 2164 return sizeof(void*); 2165 } 2166 2167 2168 SBModule 2169 SBTarget::GetModuleAtIndex (uint32_t idx) 2170 { 2171 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2172 2173 SBModule sb_module; 2174 ModuleSP module_sp; 2175 TargetSP target_sp(GetSP()); 2176 if (target_sp) 2177 { 2178 // The module list is thread safe, no need to lock 2179 module_sp = target_sp->GetImages().GetModuleAtIndex(idx); 2180 sb_module.SetSP (module_sp); 2181 } 2182 2183 if (log) 2184 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", 2185 static_cast<void*>(target_sp.get()), idx, 2186 static_cast<void*>(module_sp.get())); 2187 2188 return sb_module; 2189 } 2190 2191 bool 2192 SBTarget::RemoveModule (lldb::SBModule module) 2193 { 2194 TargetSP target_sp(GetSP()); 2195 if (target_sp) 2196 return target_sp->GetImages().Remove(module.GetSP()); 2197 return false; 2198 } 2199 2200 2201 SBBroadcaster 2202 SBTarget::GetBroadcaster () const 2203 { 2204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2205 2206 TargetSP target_sp(GetSP()); 2207 SBBroadcaster broadcaster(target_sp.get(), false); 2208 2209 if (log) 2210 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", 2211 static_cast<void*>(target_sp.get()), 2212 static_cast<void*>(broadcaster.get())); 2213 2214 return broadcaster; 2215 } 2216 2217 bool 2218 SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) 2219 { 2220 Stream &strm = description.ref(); 2221 2222 TargetSP target_sp(GetSP()); 2223 if (target_sp) 2224 { 2225 target_sp->Dump (&strm, description_level); 2226 } 2227 else 2228 strm.PutCString ("No value"); 2229 2230 return true; 2231 } 2232 2233 lldb::SBSymbolContextList 2234 SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) 2235 { 2236 lldb::SBSymbolContextList sb_sc_list; 2237 if (name && name[0]) 2238 { 2239 TargetSP target_sp(GetSP()); 2240 if (target_sp) 2241 { 2242 const bool symbols_ok = true; 2243 const bool inlines_ok = true; 2244 const bool append = true; 2245 target_sp->GetImages().FindFunctions (ConstString(name), 2246 name_type_mask, 2247 symbols_ok, 2248 inlines_ok, 2249 append, 2250 *sb_sc_list); 2251 } 2252 } 2253 return sb_sc_list; 2254 } 2255 2256 lldb::SBSymbolContextList 2257 SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype) 2258 { 2259 lldb::SBSymbolContextList sb_sc_list; 2260 if (name && name[0]) 2261 { 2262 TargetSP target_sp(GetSP()); 2263 if (target_sp) 2264 { 2265 std::string regexstr; 2266 switch (matchtype) 2267 { 2268 case eMatchTypeRegex: 2269 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list); 2270 break; 2271 case eMatchTypeStartsWith: 2272 regexstr = llvm::Regex::escape(name) + ".*"; 2273 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list); 2274 break; 2275 default: 2276 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list); 2277 break; 2278 } 2279 } 2280 } 2281 return sb_sc_list; 2282 } 2283 2284 lldb::SBType 2285 SBTarget::FindFirstType (const char* typename_cstr) 2286 { 2287 TargetSP target_sp(GetSP()); 2288 if (typename_cstr && typename_cstr[0] && target_sp) 2289 { 2290 ConstString const_typename(typename_cstr); 2291 SymbolContext sc; 2292 const bool exact_match = false; 2293 2294 const ModuleList &module_list = target_sp->GetImages(); 2295 size_t count = module_list.GetSize(); 2296 for (size_t idx = 0; idx < count; idx++) 2297 { 2298 ModuleSP module_sp (module_list.GetModuleAtIndex(idx)); 2299 if (module_sp) 2300 { 2301 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match)); 2302 if (type_sp) 2303 return SBType(type_sp); 2304 } 2305 } 2306 2307 // Didn't find the type in the symbols; try the Objective-C runtime 2308 // if one is installed 2309 2310 ProcessSP process_sp(target_sp->GetProcessSP()); 2311 2312 if (process_sp) 2313 { 2314 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); 2315 2316 if (objc_language_runtime) 2317 { 2318 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); 2319 2320 if (objc_decl_vendor) 2321 { 2322 std::vector <clang::NamedDecl *> decls; 2323 2324 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) 2325 { 2326 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0])) 2327 { 2328 return SBType(type); 2329 } 2330 } 2331 } 2332 } 2333 } 2334 2335 // No matches, search for basic typename matches 2336 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 2337 if (clang_ast) 2338 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)); 2339 } 2340 return SBType(); 2341 } 2342 2343 SBType 2344 SBTarget::GetBasicType(lldb::BasicType type) 2345 { 2346 TargetSP target_sp(GetSP()); 2347 if (target_sp) 2348 { 2349 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 2350 if (clang_ast) 2351 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type)); 2352 } 2353 return SBType(); 2354 } 2355 2356 2357 lldb::SBTypeList 2358 SBTarget::FindTypes (const char* typename_cstr) 2359 { 2360 SBTypeList sb_type_list; 2361 TargetSP target_sp(GetSP()); 2362 if (typename_cstr && typename_cstr[0] && target_sp) 2363 { 2364 ModuleList& images = target_sp->GetImages(); 2365 ConstString const_typename(typename_cstr); 2366 bool exact_match = false; 2367 SymbolContext sc; 2368 TypeList type_list; 2369 2370 uint32_t num_matches = images.FindTypes (sc, 2371 const_typename, 2372 exact_match, 2373 UINT32_MAX, 2374 type_list); 2375 2376 if (num_matches > 0) 2377 { 2378 for (size_t idx = 0; idx < num_matches; idx++) 2379 { 2380 TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 2381 if (type_sp) 2382 sb_type_list.Append(SBType(type_sp)); 2383 } 2384 } 2385 2386 // Try the Objective-C runtime if one is installed 2387 2388 ProcessSP process_sp(target_sp->GetProcessSP()); 2389 2390 if (process_sp) 2391 { 2392 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); 2393 2394 if (objc_language_runtime) 2395 { 2396 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); 2397 2398 if (objc_decl_vendor) 2399 { 2400 std::vector <clang::NamedDecl *> decls; 2401 2402 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) 2403 { 2404 for (clang::NamedDecl *decl : decls) 2405 { 2406 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl)) 2407 { 2408 sb_type_list.Append(SBType(type)); 2409 } 2410 } 2411 } 2412 } 2413 } 2414 } 2415 2416 if (sb_type_list.GetSize() == 0) 2417 { 2418 // No matches, search for basic typename matches 2419 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 2420 if (clang_ast) 2421 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename))); 2422 } 2423 } 2424 return sb_type_list; 2425 } 2426 2427 SBValueList 2428 SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) 2429 { 2430 SBValueList sb_value_list; 2431 2432 TargetSP target_sp(GetSP()); 2433 if (name && target_sp) 2434 { 2435 VariableList variable_list; 2436 const bool append = true; 2437 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), 2438 append, 2439 max_matches, 2440 variable_list); 2441 2442 if (match_count > 0) 2443 { 2444 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 2445 if (exe_scope == NULL) 2446 exe_scope = target_sp.get(); 2447 for (uint32_t i=0; i<match_count; ++i) 2448 { 2449 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); 2450 if (valobj_sp) 2451 sb_value_list.Append(SBValue(valobj_sp)); 2452 } 2453 } 2454 } 2455 2456 return sb_value_list; 2457 } 2458 2459 SBValueList 2460 SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype) 2461 { 2462 SBValueList sb_value_list; 2463 2464 TargetSP target_sp(GetSP()); 2465 if (name && target_sp) 2466 { 2467 VariableList variable_list; 2468 const bool append = true; 2469 2470 std::string regexstr; 2471 uint32_t match_count; 2472 switch (matchtype) 2473 { 2474 case eMatchTypeNormal: 2475 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name), 2476 append, 2477 max_matches, 2478 variable_list); 2479 break; 2480 case eMatchTypeRegex: 2481 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name), 2482 append, 2483 max_matches, 2484 variable_list); 2485 break; 2486 case eMatchTypeStartsWith: 2487 regexstr = llvm::Regex::escape(name) + ".*"; 2488 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()), 2489 append, 2490 max_matches, 2491 variable_list); 2492 break; 2493 } 2494 2495 2496 if (match_count > 0) 2497 { 2498 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 2499 if (exe_scope == NULL) 2500 exe_scope = target_sp.get(); 2501 for (uint32_t i = 0; i<match_count; ++i) 2502 { 2503 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i))); 2504 if (valobj_sp) 2505 sb_value_list.Append(SBValue(valobj_sp)); 2506 } 2507 } 2508 } 2509 2510 return sb_value_list; 2511 } 2512 2513 2514 lldb::SBValue 2515 SBTarget::FindFirstGlobalVariable (const char* name) 2516 { 2517 SBValueList sb_value_list(FindGlobalVariables(name, 1)); 2518 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 2519 return sb_value_list.GetValueAtIndex(0); 2520 return SBValue(); 2521 } 2522 2523 SBSourceManager 2524 SBTarget::GetSourceManager() 2525 { 2526 SBSourceManager source_manager (*this); 2527 return source_manager; 2528 } 2529 2530 lldb::SBInstructionList 2531 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count) 2532 { 2533 return ReadInstructions (base_addr, count, NULL); 2534 } 2535 2536 lldb::SBInstructionList 2537 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string) 2538 { 2539 SBInstructionList sb_instructions; 2540 2541 TargetSP target_sp(GetSP()); 2542 if (target_sp) 2543 { 2544 Address *addr_ptr = base_addr.get(); 2545 2546 if (addr_ptr) 2547 { 2548 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); 2549 bool prefer_file_cache = false; 2550 lldb_private::Error error; 2551 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; 2552 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, 2553 prefer_file_cache, 2554 data.GetBytes(), 2555 data.GetByteSize(), 2556 error, 2557 &load_addr); 2558 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; 2559 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), 2560 NULL, 2561 flavor_string, 2562 *addr_ptr, 2563 data.GetBytes(), 2564 bytes_read, 2565 count, 2566 data_from_file)); 2567 } 2568 } 2569 2570 return sb_instructions; 2571 2572 } 2573 2574 lldb::SBInstructionList 2575 SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) 2576 { 2577 return GetInstructionsWithFlavor (base_addr, NULL, buf, size); 2578 } 2579 2580 lldb::SBInstructionList 2581 SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size) 2582 { 2583 SBInstructionList sb_instructions; 2584 2585 TargetSP target_sp(GetSP()); 2586 if (target_sp) 2587 { 2588 Address addr; 2589 2590 if (base_addr.get()) 2591 addr = *base_addr.get(); 2592 2593 const bool data_from_file = true; 2594 2595 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), 2596 NULL, 2597 flavor_string, 2598 addr, 2599 buf, 2600 size, 2601 UINT32_MAX, 2602 data_from_file)); 2603 } 2604 2605 return sb_instructions; 2606 } 2607 2608 lldb::SBInstructionList 2609 SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) 2610 { 2611 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size); 2612 } 2613 2614 lldb::SBInstructionList 2615 SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size) 2616 { 2617 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size); 2618 } 2619 2620 SBError 2621 SBTarget::SetSectionLoadAddress (lldb::SBSection section, 2622 lldb::addr_t section_base_addr) 2623 { 2624 SBError sb_error; 2625 TargetSP target_sp(GetSP()); 2626 if (target_sp) 2627 { 2628 if (!section.IsValid()) 2629 { 2630 sb_error.SetErrorStringWithFormat ("invalid section"); 2631 } 2632 else 2633 { 2634 SectionSP section_sp (section.GetSP()); 2635 if (section_sp) 2636 { 2637 if (section_sp->IsThreadSpecific()) 2638 { 2639 sb_error.SetErrorString ("thread specific sections are not yet supported"); 2640 } 2641 else 2642 { 2643 ProcessSP process_sp (target_sp->GetProcessSP()); 2644 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr)) 2645 { 2646 // Flush info in the process (stack frames, etc) 2647 if (process_sp) 2648 process_sp->Flush(); 2649 } 2650 } 2651 } 2652 } 2653 } 2654 else 2655 { 2656 sb_error.SetErrorString ("invalid target"); 2657 } 2658 return sb_error; 2659 } 2660 2661 SBError 2662 SBTarget::ClearSectionLoadAddress (lldb::SBSection section) 2663 { 2664 SBError sb_error; 2665 2666 TargetSP target_sp(GetSP()); 2667 if (target_sp) 2668 { 2669 if (!section.IsValid()) 2670 { 2671 sb_error.SetErrorStringWithFormat ("invalid section"); 2672 } 2673 else 2674 { 2675 ProcessSP process_sp (target_sp->GetProcessSP()); 2676 if (target_sp->SetSectionUnloaded (section.GetSP())) 2677 { 2678 // Flush info in the process (stack frames, etc) 2679 if (process_sp) 2680 process_sp->Flush(); 2681 } 2682 } 2683 } 2684 else 2685 { 2686 sb_error.SetErrorStringWithFormat ("invalid target"); 2687 } 2688 return sb_error; 2689 } 2690 2691 SBError 2692 SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) 2693 { 2694 SBError sb_error; 2695 2696 TargetSP target_sp(GetSP()); 2697 if (target_sp) 2698 { 2699 ModuleSP module_sp (module.GetSP()); 2700 if (module_sp) 2701 { 2702 bool changed = false; 2703 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed)) 2704 { 2705 // The load was successful, make sure that at least some sections 2706 // changed before we notify that our module was loaded. 2707 if (changed) 2708 { 2709 ModuleList module_list; 2710 module_list.Append(module_sp); 2711 target_sp->ModulesDidLoad (module_list); 2712 // Flush info in the process (stack frames, etc) 2713 ProcessSP process_sp (target_sp->GetProcessSP()); 2714 if (process_sp) 2715 process_sp->Flush(); 2716 } 2717 } 2718 } 2719 else 2720 { 2721 sb_error.SetErrorStringWithFormat ("invalid module"); 2722 } 2723 2724 } 2725 else 2726 { 2727 sb_error.SetErrorStringWithFormat ("invalid target"); 2728 } 2729 return sb_error; 2730 } 2731 2732 SBError 2733 SBTarget::ClearModuleLoadAddress (lldb::SBModule module) 2734 { 2735 SBError sb_error; 2736 2737 char path[PATH_MAX]; 2738 TargetSP target_sp(GetSP()); 2739 if (target_sp) 2740 { 2741 ModuleSP module_sp (module.GetSP()); 2742 if (module_sp) 2743 { 2744 ObjectFile *objfile = module_sp->GetObjectFile(); 2745 if (objfile) 2746 { 2747 SectionList *section_list = objfile->GetSectionList(); 2748 if (section_list) 2749 { 2750 ProcessSP process_sp (target_sp->GetProcessSP()); 2751 2752 bool changed = false; 2753 const size_t num_sections = section_list->GetSize(); 2754 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) 2755 { 2756 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); 2757 if (section_sp) 2758 changed |= target_sp->SetSectionUnloaded (section_sp); 2759 } 2760 if (changed) 2761 { 2762 // Flush info in the process (stack frames, etc) 2763 ProcessSP process_sp (target_sp->GetProcessSP()); 2764 if (process_sp) 2765 process_sp->Flush(); 2766 } 2767 } 2768 else 2769 { 2770 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 2771 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); 2772 } 2773 } 2774 else 2775 { 2776 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 2777 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); 2778 } 2779 } 2780 else 2781 { 2782 sb_error.SetErrorStringWithFormat ("invalid module"); 2783 } 2784 } 2785 else 2786 { 2787 sb_error.SetErrorStringWithFormat ("invalid target"); 2788 } 2789 return sb_error; 2790 } 2791 2792 2793 lldb::SBSymbolContextList 2794 SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type) 2795 { 2796 SBSymbolContextList sb_sc_list; 2797 if (name && name[0]) 2798 { 2799 TargetSP target_sp(GetSP()); 2800 if (target_sp) 2801 { 2802 bool append = true; 2803 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name), 2804 symbol_type, 2805 *sb_sc_list, 2806 append); 2807 } 2808 } 2809 return sb_sc_list; 2810 2811 } 2812 2813 2814 lldb::SBValue 2815 SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 2816 { 2817 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2818 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 2819 SBValue expr_result; 2820 ExpressionResults exe_results = eExpressionSetupError; 2821 ValueObjectSP expr_value_sp; 2822 TargetSP target_sp(GetSP()); 2823 StackFrame *frame = NULL; 2824 if (target_sp) 2825 { 2826 if (expr == NULL || expr[0] == '\0') 2827 { 2828 if (log) 2829 log->Printf ("SBTarget::EvaluateExpression called with an empty expression"); 2830 return expr_result; 2831 } 2832 2833 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 2834 ExecutionContext exe_ctx (m_opaque_sp.get()); 2835 2836 if (log) 2837 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr); 2838 2839 frame = exe_ctx.GetFramePtr(); 2840 Target *target = exe_ctx.GetTargetPtr(); 2841 2842 if (target) 2843 { 2844 #ifdef LLDB_CONFIGURATION_DEBUG 2845 StreamString frame_description; 2846 if (frame) 2847 frame->DumpUsingSettingsFormat (&frame_description); 2848 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 2849 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 2850 #endif 2851 exe_results = target->EvaluateExpression (expr, 2852 frame, 2853 expr_value_sp, 2854 options.ref()); 2855 2856 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 2857 #ifdef LLDB_CONFIGURATION_DEBUG 2858 Host::SetCrashDescription (NULL); 2859 #endif 2860 } 2861 else 2862 { 2863 if (log) 2864 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget."); 2865 } 2866 } 2867 #ifndef LLDB_DISABLE_PYTHON 2868 if (expr_log) 2869 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **", 2870 expr_result.GetValue(), expr_result.GetSummary()); 2871 2872 if (log) 2873 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 2874 static_cast<void*>(frame), expr, 2875 static_cast<void*>(expr_value_sp.get()), exe_results); 2876 #endif 2877 2878 return expr_result; 2879 } 2880 2881 2882 lldb::addr_t 2883 SBTarget::GetStackRedZoneSize() 2884 { 2885 TargetSP target_sp(GetSP()); 2886 if (target_sp) 2887 { 2888 ABISP abi_sp; 2889 ProcessSP process_sp (target_sp->GetProcessSP()); 2890 if (process_sp) 2891 abi_sp = process_sp->GetABI(); 2892 else 2893 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture()); 2894 if (abi_sp) 2895 return abi_sp->GetRedZoneSize(); 2896 } 2897 return 0; 2898 } 2899 2900