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/API/SBTarget.h" 11 12 #include "lldb/lldb-public.h" 13 14 #include "lldb/API/SBDebugger.h" 15 #include "lldb/API/SBBreakpoint.h" 16 #include "lldb/API/SBFileSpec.h" 17 #include "lldb/API/SBListener.h" 18 #include "lldb/API/SBModule.h" 19 #include "lldb/API/SBSourceManager.h" 20 #include "lldb/API/SBProcess.h" 21 #include "lldb/API/SBStream.h" 22 #include "lldb/API/SBSymbolContextList.h" 23 #include "lldb/Breakpoint/BreakpointID.h" 24 #include "lldb/Breakpoint/BreakpointIDList.h" 25 #include "lldb/Breakpoint/BreakpointList.h" 26 #include "lldb/Breakpoint/BreakpointLocation.h" 27 #include "lldb/Core/Address.h" 28 #include "lldb/Core/AddressResolver.h" 29 #include "lldb/Core/AddressResolverName.h" 30 #include "lldb/Core/ArchSpec.h" 31 #include "lldb/Core/Debugger.h" 32 #include "lldb/Core/Disassembler.h" 33 #include "lldb/Core/Log.h" 34 #include "lldb/Core/RegularExpression.h" 35 #include "lldb/Core/SearchFilter.h" 36 #include "lldb/Core/STLUtils.h" 37 #include "lldb/Core/ValueObjectList.h" 38 #include "lldb/Core/ValueObjectVariable.h" 39 #include "lldb/Host/FileSpec.h" 40 #include "lldb/Host/Host.h" 41 #include "lldb/Interpreter/Args.h" 42 #include "lldb/Symbol/SymbolVendor.h" 43 #include "lldb/Symbol/VariableList.h" 44 #include "lldb/Target/Process.h" 45 #include "lldb/Target/Target.h" 46 #include "lldb/Target/TargetList.h" 47 48 #include "lldb/Interpreter/CommandReturnObject.h" 49 #include "../source/Commands/CommandObjectBreakpoint.h" 50 51 52 using namespace lldb; 53 using namespace lldb_private; 54 55 #define DEFAULT_DISASM_BYTE_SIZE 32 56 57 //---------------------------------------------------------------------- 58 // SBTarget constructor 59 //---------------------------------------------------------------------- 60 SBTarget::SBTarget () : 61 m_opaque_sp () 62 { 63 } 64 65 SBTarget::SBTarget (const SBTarget& rhs) : 66 m_opaque_sp (rhs.m_opaque_sp) 67 { 68 } 69 70 SBTarget::SBTarget(const TargetSP& target_sp) : 71 m_opaque_sp (target_sp) 72 { 73 } 74 75 const SBTarget& 76 SBTarget::operator = (const SBTarget& rhs) 77 { 78 if (this != &rhs) 79 m_opaque_sp = rhs.m_opaque_sp; 80 return *this; 81 } 82 83 //---------------------------------------------------------------------- 84 // Destructor 85 //---------------------------------------------------------------------- 86 SBTarget::~SBTarget() 87 { 88 } 89 90 const char * 91 SBTarget::GetBroadcasterClassName () 92 { 93 return Target::GetStaticBroadcasterClass().AsCString(); 94 } 95 96 bool 97 SBTarget::IsValid () const 98 { 99 return m_opaque_sp.get() != NULL; 100 } 101 102 SBProcess 103 SBTarget::GetProcess () 104 { 105 SBProcess sb_process; 106 ProcessSP process_sp; 107 TargetSP target_sp(GetSP()); 108 if (target_sp) 109 { 110 process_sp = target_sp->GetProcessSP(); 111 sb_process.SetSP (process_sp); 112 } 113 114 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 115 if (log) 116 { 117 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", 118 target_sp.get(), process_sp.get()); 119 } 120 121 return sb_process; 122 } 123 124 SBDebugger 125 SBTarget::GetDebugger () const 126 { 127 SBDebugger debugger; 128 TargetSP target_sp(GetSP()); 129 if (target_sp) 130 debugger.reset (target_sp->GetDebugger().shared_from_this()); 131 return debugger; 132 } 133 134 SBProcess 135 SBTarget::LaunchSimple 136 ( 137 char const **argv, 138 char const **envp, 139 const char *working_directory 140 ) 141 { 142 char *stdin_path = NULL; 143 char *stdout_path = NULL; 144 char *stderr_path = NULL; 145 uint32_t launch_flags = 0; 146 bool stop_at_entry = false; 147 SBError error; 148 SBListener listener = GetDebugger().GetListener(); 149 return Launch (listener, 150 argv, 151 envp, 152 stdin_path, 153 stdout_path, 154 stderr_path, 155 working_directory, 156 launch_flags, 157 stop_at_entry, 158 error); 159 } 160 161 SBProcess 162 SBTarget::Launch 163 ( 164 SBListener &listener, 165 char const **argv, 166 char const **envp, 167 const char *stdin_path, 168 const char *stdout_path, 169 const char *stderr_path, 170 const char *working_directory, 171 uint32_t launch_flags, // See LaunchFlags 172 bool stop_at_entry, 173 lldb::SBError& error 174 ) 175 { 176 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 177 178 SBProcess sb_process; 179 ProcessSP process_sp; 180 TargetSP target_sp(GetSP()); 181 182 if (log) 183 { 184 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))...", 185 target_sp.get(), 186 argv, 187 envp, 188 stdin_path ? stdin_path : "NULL", 189 stdout_path ? stdout_path : "NULL", 190 stderr_path ? stderr_path : "NULL", 191 working_directory ? working_directory : "NULL", 192 launch_flags, 193 stop_at_entry, 194 error.get()); 195 } 196 197 if (target_sp) 198 { 199 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 200 201 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) 202 launch_flags |= eLaunchFlagDisableASLR; 203 204 StateType state = eStateInvalid; 205 process_sp = target_sp->GetProcessSP(); 206 if (process_sp) 207 { 208 state = process_sp->GetState(); 209 210 if (process_sp->IsAlive() && state != eStateConnected) 211 { 212 if (state == eStateAttaching) 213 error.SetErrorString ("process attach is in progress"); 214 else 215 error.SetErrorString ("a process is already being debugged"); 216 return sb_process; 217 } 218 } 219 220 if (state == eStateConnected) 221 { 222 // If we are already connected, then we have already specified the 223 // listener, so if a valid listener is supplied, we need to error out 224 // to let the client know. 225 if (listener.IsValid()) 226 { 227 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 228 return sb_process; 229 } 230 } 231 else 232 { 233 if (listener.IsValid()) 234 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); 235 else 236 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 237 } 238 239 if (process_sp) 240 { 241 sb_process.SetSP (process_sp); 242 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) 243 launch_flags |= eLaunchFlagDisableSTDIO; 244 245 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); 246 247 Module *exe_module = target_sp->GetExecutableModulePointer(); 248 if (exe_module) 249 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 250 if (argv) 251 launch_info.GetArguments().AppendArguments (argv); 252 if (envp) 253 launch_info.GetEnvironmentEntries ().SetArguments (envp); 254 255 error.SetError (process_sp->Launch (launch_info)); 256 if (error.Success()) 257 { 258 // We we are stopping at the entry point, we can return now! 259 if (stop_at_entry) 260 return sb_process; 261 262 // Make sure we are stopped at the entry 263 StateType state = process_sp->WaitForProcessToStop (NULL); 264 if (state == eStateStopped) 265 { 266 // resume the process to skip the entry point 267 error.SetError (process_sp->Resume()); 268 if (error.Success()) 269 { 270 // If we are doing synchronous mode, then wait for the 271 // process to stop yet again! 272 if (target_sp->GetDebugger().GetAsyncExecution () == false) 273 process_sp->WaitForProcessToStop (NULL); 274 } 275 } 276 } 277 } 278 else 279 { 280 error.SetErrorString ("unable to create lldb_private::Process"); 281 } 282 } 283 else 284 { 285 error.SetErrorString ("SBTarget is invalid"); 286 } 287 288 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 289 if (log) 290 { 291 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", 292 target_sp.get(), process_sp.get()); 293 } 294 295 return sb_process; 296 } 297 298 #if defined(__APPLE__) 299 300 lldb::SBProcess 301 SBTarget::AttachToProcessWithID (SBListener &listener, 302 ::pid_t pid, 303 lldb::SBError& error) 304 { 305 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); 306 } 307 308 #endif // #if defined(__APPLE__) 309 310 lldb::SBProcess 311 SBTarget::AttachToProcessWithID 312 ( 313 SBListener &listener, 314 lldb::pid_t pid,// The process ID to attach to 315 SBError& error // An error explaining what went wrong if attach fails 316 ) 317 { 318 SBProcess sb_process; 319 ProcessSP process_sp; 320 TargetSP target_sp(GetSP()); 321 if (target_sp) 322 { 323 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 324 325 StateType state = eStateInvalid; 326 process_sp = target_sp->GetProcessSP(); 327 if (process_sp) 328 { 329 state = process_sp->GetState(); 330 331 if (process_sp->IsAlive() && state != eStateConnected) 332 { 333 if (state == eStateAttaching) 334 error.SetErrorString ("process attach is in progress"); 335 else 336 error.SetErrorString ("a process is already being debugged"); 337 return sb_process; 338 } 339 } 340 341 if (state == eStateConnected) 342 { 343 // If we are already connected, then we have already specified the 344 // listener, so if a valid listener is supplied, we need to error out 345 // to let the client know. 346 if (listener.IsValid()) 347 { 348 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 349 return sb_process; 350 } 351 } 352 else 353 { 354 if (listener.IsValid()) 355 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); 356 else 357 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 358 } 359 if (process_sp) 360 { 361 sb_process.SetSP (process_sp); 362 363 ProcessAttachInfo attach_info; 364 attach_info.SetProcessID (pid); 365 error.SetError (process_sp->Attach (attach_info)); 366 // If we are doing synchronous mode, then wait for the 367 // process to stop! 368 if (target_sp->GetDebugger().GetAsyncExecution () == false) 369 process_sp->WaitForProcessToStop (NULL); 370 } 371 else 372 { 373 error.SetErrorString ("unable to create lldb_private::Process"); 374 } 375 } 376 else 377 { 378 error.SetErrorString ("SBTarget is invalid"); 379 } 380 return sb_process; 381 382 } 383 384 lldb::SBProcess 385 SBTarget::AttachToProcessWithName 386 ( 387 SBListener &listener, 388 const char *name, // basename of process to attach to 389 bool wait_for, // if true wait for a new instance of "name" to be launched 390 SBError& error // An error explaining what went wrong if attach fails 391 ) 392 { 393 SBProcess sb_process; 394 ProcessSP process_sp; 395 TargetSP target_sp(GetSP()); 396 if (name && target_sp) 397 { 398 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 399 400 StateType state = eStateInvalid; 401 process_sp = target_sp->GetProcessSP(); 402 if (process_sp) 403 { 404 state = process_sp->GetState(); 405 406 if (process_sp->IsAlive() && state != eStateConnected) 407 { 408 if (state == eStateAttaching) 409 error.SetErrorString ("process attach is in progress"); 410 else 411 error.SetErrorString ("a process is already being debugged"); 412 return sb_process; 413 } 414 } 415 416 if (state == eStateConnected) 417 { 418 // If we are already connected, then we have already specified the 419 // listener, so if a valid listener is supplied, we need to error out 420 // to let the client know. 421 if (listener.IsValid()) 422 { 423 error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 424 return sb_process; 425 } 426 } 427 else 428 { 429 if (listener.IsValid()) 430 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); 431 else 432 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); 433 } 434 435 if (process_sp) 436 { 437 sb_process.SetSP (process_sp); 438 ProcessAttachInfo attach_info; 439 attach_info.GetExecutableFile().SetFile(name, false); 440 attach_info.SetWaitForLaunch(wait_for); 441 error.SetError (process_sp->Attach (attach_info)); 442 // If we are doing synchronous mode, then wait for the 443 // process to stop! 444 if (target_sp->GetDebugger().GetAsyncExecution () == false) 445 process_sp->WaitForProcessToStop (NULL); 446 } 447 else 448 { 449 error.SetErrorString ("unable to create lldb_private::Process"); 450 } 451 } 452 else 453 { 454 error.SetErrorString ("SBTarget is invalid"); 455 } 456 return sb_process; 457 458 } 459 460 lldb::SBProcess 461 SBTarget::ConnectRemote 462 ( 463 SBListener &listener, 464 const char *url, 465 const char *plugin_name, 466 SBError& error 467 ) 468 { 469 SBProcess sb_process; 470 ProcessSP process_sp; 471 TargetSP target_sp(GetSP()); 472 if (target_sp) 473 { 474 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 475 if (listener.IsValid()) 476 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); 477 else 478 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); 479 480 481 if (process_sp) 482 { 483 sb_process.SetSP (process_sp); 484 error.SetError (process_sp->ConnectRemote (url)); 485 } 486 else 487 { 488 error.SetErrorString ("unable to create lldb_private::Process"); 489 } 490 } 491 else 492 { 493 error.SetErrorString ("SBTarget is invalid"); 494 } 495 return sb_process; 496 } 497 498 SBFileSpec 499 SBTarget::GetExecutable () 500 { 501 502 SBFileSpec exe_file_spec; 503 TargetSP target_sp(GetSP()); 504 if (target_sp) 505 { 506 Module *exe_module = target_sp->GetExecutableModulePointer(); 507 if (exe_module) 508 exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); 509 } 510 511 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 512 if (log) 513 { 514 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", 515 target_sp.get(), exe_file_spec.get()); 516 } 517 518 return exe_file_spec; 519 } 520 521 bool 522 SBTarget::operator == (const SBTarget &rhs) const 523 { 524 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 525 } 526 527 bool 528 SBTarget::operator != (const SBTarget &rhs) const 529 { 530 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 531 } 532 533 lldb::TargetSP 534 SBTarget::GetSP () const 535 { 536 return m_opaque_sp; 537 } 538 539 void 540 SBTarget::SetSP (const lldb::TargetSP& target_sp) 541 { 542 m_opaque_sp = target_sp; 543 } 544 545 lldb::SBAddress 546 SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) 547 { 548 lldb::SBAddress sb_addr; 549 Address &addr = sb_addr.ref(); 550 TargetSP target_sp(GetSP()); 551 if (target_sp) 552 { 553 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 554 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) 555 return sb_addr; 556 } 557 558 // We have a load address that isn't in a section, just return an address 559 // with the offset filled in (the address) and the section set to NULL 560 addr.SetSection(NULL); 561 addr.SetOffset(vm_addr); 562 return sb_addr; 563 } 564 565 SBSymbolContext 566 SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 567 { 568 SBSymbolContext sc; 569 if (addr.IsValid()) 570 { 571 TargetSP target_sp(GetSP()); 572 if (target_sp) 573 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); 574 } 575 return sc; 576 } 577 578 579 SBBreakpoint 580 SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line) 581 { 582 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); 583 } 584 585 SBBreakpoint 586 SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line) 587 { 588 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 589 590 SBBreakpoint sb_bp; 591 TargetSP target_sp(GetSP()); 592 if (target_sp && line != 0) 593 { 594 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 595 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); 596 } 597 598 if (log) 599 { 600 SBStream sstr; 601 sb_bp.GetDescription (sstr); 602 char path[PATH_MAX]; 603 sb_file_spec->GetPath (path, sizeof(path)); 604 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", 605 target_sp.get(), 606 path, 607 line, 608 sb_bp.get(), 609 sstr.GetData()); 610 } 611 612 return sb_bp; 613 } 614 615 SBBreakpoint 616 SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name) 617 { 618 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 619 620 SBBreakpoint sb_bp; 621 TargetSP target_sp(GetSP()); 622 if (target_sp.get()) 623 { 624 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 625 if (module_name && module_name[0]) 626 { 627 FileSpecList module_spec_list; 628 module_spec_list.Append (FileSpec (module_name, false)); 629 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false); 630 } 631 else 632 { 633 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false); 634 } 635 } 636 637 if (log) 638 { 639 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", 640 target_sp.get(), symbol_name, module_name, sb_bp.get()); 641 } 642 643 return sb_bp; 644 } 645 646 lldb::SBBreakpoint 647 SBTarget::BreakpointCreateByName (const char *symbol_name, 648 const SBFileSpecList &module_list, 649 const SBFileSpecList &comp_unit_list) 650 { 651 uint32_t name_type_mask = eFunctionNameTypeAuto; 652 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); 653 } 654 655 lldb::SBBreakpoint 656 SBTarget::BreakpointCreateByName (const char *symbol_name, 657 uint32_t name_type_mask, 658 const SBFileSpecList &module_list, 659 const SBFileSpecList &comp_unit_list) 660 { 661 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 662 663 SBBreakpoint sb_bp; 664 TargetSP target_sp(GetSP()); 665 if (target_sp && symbol_name && symbol_name[0]) 666 { 667 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 668 *sb_bp = target_sp->CreateBreakpoint (module_list.get(), 669 comp_unit_list.get(), 670 symbol_name, 671 name_type_mask, 672 false); 673 } 674 675 if (log) 676 { 677 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", 678 target_sp.get(), symbol_name, name_type_mask, sb_bp.get()); 679 } 680 681 return sb_bp; 682 } 683 684 685 SBBreakpoint 686 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name) 687 { 688 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 689 690 SBBreakpoint sb_bp; 691 TargetSP target_sp(GetSP()); 692 if (target_sp && symbol_name_regex && symbol_name_regex[0]) 693 { 694 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 695 RegularExpression regexp(symbol_name_regex); 696 697 if (module_name && module_name[0]) 698 { 699 FileSpecList module_spec_list; 700 module_spec_list.Append (FileSpec (module_name, false)); 701 702 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false); 703 } 704 else 705 { 706 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false); 707 } 708 } 709 710 if (log) 711 { 712 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", 713 target_sp.get(), symbol_name_regex, module_name, sb_bp.get()); 714 } 715 716 return sb_bp; 717 } 718 719 lldb::SBBreakpoint 720 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 721 const SBFileSpecList &module_list, 722 const SBFileSpecList &comp_unit_list) 723 { 724 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 725 726 SBBreakpoint sb_bp; 727 TargetSP target_sp(GetSP()); 728 if (target_sp && symbol_name_regex && symbol_name_regex[0]) 729 { 730 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 731 RegularExpression regexp(symbol_name_regex); 732 733 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false); 734 } 735 736 if (log) 737 { 738 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", 739 target_sp.get(), symbol_name_regex, sb_bp.get()); 740 } 741 742 return sb_bp; 743 } 744 745 SBBreakpoint 746 SBTarget::BreakpointCreateByAddress (addr_t address) 747 { 748 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 749 750 SBBreakpoint sb_bp; 751 TargetSP target_sp(GetSP()); 752 if (target_sp) 753 { 754 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 755 *sb_bp = target_sp->CreateBreakpoint (address, false); 756 } 757 758 if (log) 759 { 760 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get()); 761 } 762 763 return sb_bp; 764 } 765 766 lldb::SBBreakpoint 767 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name) 768 { 769 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 770 771 SBBreakpoint sb_bp; 772 TargetSP target_sp(GetSP()); 773 if (target_sp && source_regex && source_regex[0]) 774 { 775 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 776 RegularExpression regexp(source_regex); 777 FileSpecList source_file_spec_list; 778 source_file_spec_list.Append (source_file.ref()); 779 780 if (module_name && module_name[0]) 781 { 782 FileSpecList module_spec_list; 783 module_spec_list.Append (FileSpec (module_name, false)); 784 785 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); 786 } 787 else 788 { 789 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); 790 } 791 } 792 793 if (log) 794 { 795 char path[PATH_MAX]; 796 source_file->GetPath (path, sizeof(path)); 797 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", 798 target_sp.get(), source_regex, path, module_name, sb_bp.get()); 799 } 800 801 return sb_bp; 802 } 803 804 lldb::SBBreakpoint 805 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, 806 const SBFileSpecList &module_list, 807 const lldb::SBFileSpecList &source_file_list) 808 { 809 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 810 811 SBBreakpoint sb_bp; 812 TargetSP target_sp(GetSP()); 813 if (target_sp && source_regex && source_regex[0]) 814 { 815 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 816 RegularExpression regexp(source_regex); 817 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); 818 } 819 820 if (log) 821 { 822 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", 823 target_sp.get(), source_regex, sb_bp.get()); 824 } 825 826 return sb_bp; 827 } 828 829 uint32_t 830 SBTarget::GetNumBreakpoints () const 831 { 832 TargetSP target_sp(GetSP()); 833 if (target_sp) 834 { 835 // The breakpoint list is thread safe, no need to lock 836 return target_sp->GetBreakpointList().GetSize(); 837 } 838 return 0; 839 } 840 841 SBBreakpoint 842 SBTarget::GetBreakpointAtIndex (uint32_t idx) const 843 { 844 SBBreakpoint sb_breakpoint; 845 TargetSP target_sp(GetSP()); 846 if (target_sp) 847 { 848 // The breakpoint list is thread safe, no need to lock 849 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); 850 } 851 return sb_breakpoint; 852 } 853 854 bool 855 SBTarget::BreakpointDelete (break_id_t bp_id) 856 { 857 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 858 859 bool result = false; 860 TargetSP target_sp(GetSP()); 861 if (target_sp) 862 { 863 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 864 result = target_sp->RemoveBreakpointByID (bp_id); 865 } 866 867 if (log) 868 { 869 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result); 870 } 871 872 return result; 873 } 874 875 SBBreakpoint 876 SBTarget::FindBreakpointByID (break_id_t bp_id) 877 { 878 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 879 880 SBBreakpoint sb_breakpoint; 881 TargetSP target_sp(GetSP()); 882 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) 883 { 884 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 885 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); 886 } 887 888 if (log) 889 { 890 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", 891 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); 892 } 893 894 return sb_breakpoint; 895 } 896 897 bool 898 SBTarget::EnableAllBreakpoints () 899 { 900 TargetSP target_sp(GetSP()); 901 if (target_sp) 902 { 903 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 904 target_sp->EnableAllBreakpoints (); 905 return true; 906 } 907 return false; 908 } 909 910 bool 911 SBTarget::DisableAllBreakpoints () 912 { 913 TargetSP target_sp(GetSP()); 914 if (target_sp) 915 { 916 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 917 target_sp->DisableAllBreakpoints (); 918 return true; 919 } 920 return false; 921 } 922 923 bool 924 SBTarget::DeleteAllBreakpoints () 925 { 926 TargetSP target_sp(GetSP()); 927 if (target_sp) 928 { 929 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 930 target_sp->RemoveAllBreakpoints (); 931 return true; 932 } 933 return false; 934 } 935 936 uint32_t 937 SBTarget::GetNumWatchpoints () const 938 { 939 TargetSP target_sp(GetSP()); 940 if (target_sp) 941 { 942 // The watchpoint list is thread safe, no need to lock 943 return target_sp->GetWatchpointList().GetSize(); 944 } 945 return 0; 946 } 947 948 SBWatchpoint 949 SBTarget::GetWatchpointAtIndex (uint32_t idx) const 950 { 951 SBWatchpoint sb_watchpoint; 952 TargetSP target_sp(GetSP()); 953 if (target_sp) 954 { 955 // The watchpoint list is thread safe, no need to lock 956 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); 957 } 958 return sb_watchpoint; 959 } 960 961 bool 962 SBTarget::DeleteWatchpoint (watch_id_t wp_id) 963 { 964 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 965 966 bool result = false; 967 TargetSP target_sp(GetSP()); 968 if (target_sp) 969 { 970 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 971 result = target_sp->RemoveWatchpointByID (wp_id); 972 } 973 974 if (log) 975 { 976 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result); 977 } 978 979 return result; 980 } 981 982 SBWatchpoint 983 SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) 984 { 985 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 986 987 SBWatchpoint sb_watchpoint; 988 lldb::WatchpointSP watchpoint_sp; 989 TargetSP target_sp(GetSP()); 990 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) 991 { 992 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 993 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); 994 sb_watchpoint.SetSP (watchpoint_sp); 995 } 996 997 if (log) 998 { 999 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", 1000 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get()); 1001 } 1002 1003 return sb_watchpoint; 1004 } 1005 1006 lldb::SBWatchpoint 1007 SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write) 1008 { 1009 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1010 1011 SBWatchpoint sb_watchpoint; 1012 lldb::WatchpointSP watchpoint_sp; 1013 TargetSP target_sp(GetSP()); 1014 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) 1015 { 1016 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1017 uint32_t watch_type = 0; 1018 if (read) 1019 watch_type |= LLDB_WATCH_TYPE_READ; 1020 if (write) 1021 watch_type |= LLDB_WATCH_TYPE_WRITE; 1022 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type); 1023 sb_watchpoint.SetSP (watchpoint_sp); 1024 } 1025 1026 if (log) 1027 { 1028 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)", 1029 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get()); 1030 } 1031 1032 return sb_watchpoint; 1033 } 1034 1035 bool 1036 SBTarget::EnableAllWatchpoints () 1037 { 1038 TargetSP target_sp(GetSP()); 1039 if (target_sp) 1040 { 1041 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1042 target_sp->EnableAllWatchpoints (); 1043 return true; 1044 } 1045 return false; 1046 } 1047 1048 bool 1049 SBTarget::DisableAllWatchpoints () 1050 { 1051 TargetSP target_sp(GetSP()); 1052 if (target_sp) 1053 { 1054 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1055 target_sp->DisableAllWatchpoints (); 1056 return true; 1057 } 1058 return false; 1059 } 1060 1061 bool 1062 SBTarget::DeleteAllWatchpoints () 1063 { 1064 TargetSP target_sp(GetSP()); 1065 if (target_sp) 1066 { 1067 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1068 target_sp->RemoveAllWatchpoints (); 1069 return true; 1070 } 1071 return false; 1072 } 1073 1074 1075 lldb::SBModule 1076 SBTarget::AddModule (const char *path, 1077 const char *triple, 1078 const char *uuid_cstr) 1079 { 1080 lldb::SBModule sb_module; 1081 TargetSP target_sp(GetSP()); 1082 if (target_sp) 1083 { 1084 FileSpec module_file_spec; 1085 UUID module_uuid; 1086 ArchSpec module_arch; 1087 1088 if (path) 1089 module_file_spec.SetFile(path, false); 1090 1091 if (uuid_cstr) 1092 module_uuid.SetfromCString(uuid_cstr); 1093 1094 if (triple) 1095 module_arch.SetTriple (triple, target_sp->GetPlatform ().get()); 1096 1097 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec, 1098 module_arch, 1099 uuid_cstr ? &module_uuid : NULL)); 1100 } 1101 return sb_module; 1102 } 1103 1104 bool 1105 SBTarget::AddModule (lldb::SBModule &module) 1106 { 1107 TargetSP target_sp(GetSP()); 1108 if (target_sp) 1109 { 1110 target_sp->GetImages().AppendIfNeeded (module.GetSP()); 1111 return true; 1112 } 1113 return false; 1114 } 1115 1116 uint32_t 1117 SBTarget::GetNumModules () const 1118 { 1119 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1120 1121 uint32_t num = 0; 1122 TargetSP target_sp(GetSP()); 1123 if (target_sp) 1124 { 1125 // The module list is thread safe, no need to lock 1126 num = target_sp->GetImages().GetSize(); 1127 } 1128 1129 if (log) 1130 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num); 1131 1132 return num; 1133 } 1134 1135 void 1136 SBTarget::Clear () 1137 { 1138 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1139 1140 if (log) 1141 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); 1142 1143 m_opaque_sp.reset(); 1144 } 1145 1146 1147 SBModule 1148 SBTarget::FindModule (const SBFileSpec &sb_file_spec) 1149 { 1150 SBModule sb_module; 1151 TargetSP target_sp(GetSP()); 1152 if (target_sp && sb_file_spec.IsValid()) 1153 { 1154 // The module list is thread safe, no need to lock 1155 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL)); 1156 } 1157 return sb_module; 1158 } 1159 1160 lldb::ByteOrder 1161 SBTarget::GetByteOrder () 1162 { 1163 TargetSP target_sp(GetSP()); 1164 if (target_sp) 1165 return target_sp->GetArchitecture().GetByteOrder(); 1166 return eByteOrderInvalid; 1167 } 1168 1169 const char * 1170 SBTarget::GetTriple () 1171 { 1172 TargetSP target_sp(GetSP()); 1173 if (target_sp) 1174 { 1175 std::string triple (target_sp->GetArchitecture().GetTriple().str()); 1176 // Unique the string so we don't run into ownership issues since 1177 // the const strings put the string into the string pool once and 1178 // the strings never comes out 1179 ConstString const_triple (triple.c_str()); 1180 return const_triple.GetCString(); 1181 } 1182 return NULL; 1183 } 1184 1185 uint32_t 1186 SBTarget::GetAddressByteSize() 1187 { 1188 TargetSP target_sp(GetSP()); 1189 if (target_sp) 1190 return target_sp->GetArchitecture().GetAddressByteSize(); 1191 return sizeof(void*); 1192 } 1193 1194 1195 SBModule 1196 SBTarget::GetModuleAtIndex (uint32_t idx) 1197 { 1198 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1199 1200 SBModule sb_module; 1201 ModuleSP module_sp; 1202 TargetSP target_sp(GetSP()); 1203 if (target_sp) 1204 { 1205 // The module list is thread safe, no need to lock 1206 module_sp = target_sp->GetImages().GetModuleAtIndex(idx); 1207 sb_module.SetSP (module_sp); 1208 } 1209 1210 if (log) 1211 { 1212 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", 1213 target_sp.get(), idx, module_sp.get()); 1214 } 1215 1216 return sb_module; 1217 } 1218 1219 bool 1220 SBTarget::RemoveModule (lldb::SBModule module) 1221 { 1222 TargetSP target_sp(GetSP()); 1223 if (target_sp) 1224 return target_sp->GetImages().Remove(module.GetSP()); 1225 return false; 1226 } 1227 1228 1229 SBBroadcaster 1230 SBTarget::GetBroadcaster () const 1231 { 1232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1233 1234 TargetSP target_sp(GetSP()); 1235 SBBroadcaster broadcaster(target_sp.get(), false); 1236 1237 if (log) 1238 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", 1239 target_sp.get(), broadcaster.get()); 1240 1241 return broadcaster; 1242 } 1243 1244 bool 1245 SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) 1246 { 1247 Stream &strm = description.ref(); 1248 1249 TargetSP target_sp(GetSP()); 1250 if (target_sp) 1251 { 1252 target_sp->Dump (&strm, description_level); 1253 } 1254 else 1255 strm.PutCString ("No value"); 1256 1257 return true; 1258 } 1259 1260 lldb::SBSymbolContextList 1261 SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) 1262 { 1263 lldb::SBSymbolContextList sb_sc_list; 1264 if (name && name[0]) 1265 { 1266 TargetSP target_sp(GetSP()); 1267 if (target_sp) 1268 { 1269 const bool symbols_ok = true; 1270 const bool inlines_ok = true; 1271 const bool append = true; 1272 target_sp->GetImages().FindFunctions (ConstString(name), 1273 name_type_mask, 1274 symbols_ok, 1275 inlines_ok, 1276 append, 1277 *sb_sc_list); 1278 } 1279 } 1280 return sb_sc_list; 1281 } 1282 1283 lldb::SBType 1284 SBTarget::FindFirstType (const char* type) 1285 { 1286 TargetSP target_sp(GetSP()); 1287 if (type && target_sp) 1288 { 1289 size_t count = target_sp->GetImages().GetSize(); 1290 for (size_t idx = 0; idx < count; idx++) 1291 { 1292 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type); 1293 1294 if (found_at_idx.IsValid()) 1295 return found_at_idx; 1296 } 1297 } 1298 return SBType(); 1299 } 1300 1301 lldb::SBTypeList 1302 SBTarget::FindTypes (const char* type) 1303 { 1304 1305 SBTypeList retval; 1306 1307 TargetSP target_sp(GetSP()); 1308 if (type && target_sp) 1309 { 1310 ModuleList& images = target_sp->GetImages(); 1311 ConstString name_const(type); 1312 SymbolContext sc; 1313 TypeList type_list; 1314 1315 uint32_t num_matches = images.FindTypes(sc, 1316 name_const, 1317 true, 1318 UINT32_MAX, 1319 type_list); 1320 1321 for (size_t idx = 0; idx < num_matches; idx++) 1322 { 1323 TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 1324 if (type_sp) 1325 retval.Append(SBType(type_sp)); 1326 } 1327 } 1328 return retval; 1329 } 1330 1331 SBValueList 1332 SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) 1333 { 1334 SBValueList sb_value_list; 1335 1336 TargetSP target_sp(GetSP()); 1337 if (name && target_sp) 1338 { 1339 VariableList variable_list; 1340 const bool append = true; 1341 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), 1342 append, 1343 max_matches, 1344 variable_list); 1345 1346 if (match_count > 0) 1347 { 1348 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 1349 if (exe_scope == NULL) 1350 exe_scope = target_sp.get(); 1351 ValueObjectList &value_object_list = sb_value_list.ref(); 1352 for (uint32_t i=0; i<match_count; ++i) 1353 { 1354 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); 1355 if (valobj_sp) 1356 value_object_list.Append(valobj_sp); 1357 } 1358 } 1359 } 1360 1361 return sb_value_list; 1362 } 1363 1364 SBSourceManager 1365 SBTarget::GetSourceManager() 1366 { 1367 SBSourceManager source_manager (*this); 1368 return source_manager; 1369 } 1370 1371 lldb::SBInstructionList 1372 SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) 1373 { 1374 SBInstructionList sb_instructions; 1375 1376 TargetSP target_sp(GetSP()); 1377 if (target_sp) 1378 { 1379 Address addr; 1380 1381 if (base_addr.get()) 1382 addr = *base_addr.get(); 1383 1384 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), 1385 NULL, 1386 addr, 1387 buf, 1388 size)); 1389 } 1390 1391 return sb_instructions; 1392 } 1393 1394 lldb::SBInstructionList 1395 SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) 1396 { 1397 return GetInstructions (ResolveLoadAddress(base_addr), buf, size); 1398 } 1399 1400 SBError 1401 SBTarget::SetSectionLoadAddress (lldb::SBSection section, 1402 lldb::addr_t section_base_addr) 1403 { 1404 SBError sb_error; 1405 TargetSP target_sp(GetSP()); 1406 if (target_sp) 1407 { 1408 if (!section.IsValid()) 1409 { 1410 sb_error.SetErrorStringWithFormat ("invalid section"); 1411 } 1412 else 1413 { 1414 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr); 1415 } 1416 } 1417 else 1418 { 1419 sb_error.SetErrorStringWithFormat ("invalid target"); 1420 } 1421 return sb_error; 1422 } 1423 1424 SBError 1425 SBTarget::ClearSectionLoadAddress (lldb::SBSection section) 1426 { 1427 SBError sb_error; 1428 1429 TargetSP target_sp(GetSP()); 1430 if (target_sp) 1431 { 1432 if (!section.IsValid()) 1433 { 1434 sb_error.SetErrorStringWithFormat ("invalid section"); 1435 } 1436 else 1437 { 1438 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection()); 1439 } 1440 } 1441 else 1442 { 1443 sb_error.SetErrorStringWithFormat ("invalid target"); 1444 } 1445 return sb_error; 1446 } 1447 1448 SBError 1449 SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) 1450 { 1451 SBError sb_error; 1452 1453 char path[PATH_MAX]; 1454 TargetSP target_sp(GetSP()); 1455 if (target_sp) 1456 { 1457 ModuleSP module_sp (module.GetSP()); 1458 if (module_sp) 1459 { 1460 ObjectFile *objfile = module_sp->GetObjectFile(); 1461 if (objfile) 1462 { 1463 SectionList *section_list = objfile->GetSectionList(); 1464 if (section_list) 1465 { 1466 const size_t num_sections = section_list->GetSize(); 1467 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) 1468 { 1469 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); 1470 if (section_sp) 1471 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); 1472 } 1473 } 1474 else 1475 { 1476 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 1477 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); 1478 } 1479 } 1480 else 1481 { 1482 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 1483 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); 1484 } 1485 } 1486 else 1487 { 1488 sb_error.SetErrorStringWithFormat ("invalid module"); 1489 } 1490 1491 } 1492 else 1493 { 1494 sb_error.SetErrorStringWithFormat ("invalid target"); 1495 } 1496 return sb_error; 1497 } 1498 1499 SBError 1500 SBTarget::ClearModuleLoadAddress (lldb::SBModule module) 1501 { 1502 SBError sb_error; 1503 1504 char path[PATH_MAX]; 1505 TargetSP target_sp(GetSP()); 1506 if (target_sp) 1507 { 1508 ModuleSP module_sp (module.GetSP()); 1509 if (module_sp) 1510 { 1511 ObjectFile *objfile = module_sp->GetObjectFile(); 1512 if (objfile) 1513 { 1514 SectionList *section_list = objfile->GetSectionList(); 1515 if (section_list) 1516 { 1517 const size_t num_sections = section_list->GetSize(); 1518 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) 1519 { 1520 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); 1521 if (section_sp) 1522 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); 1523 } 1524 } 1525 else 1526 { 1527 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 1528 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); 1529 } 1530 } 1531 else 1532 { 1533 module_sp->GetFileSpec().GetPath (path, sizeof(path)); 1534 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); 1535 } 1536 } 1537 else 1538 { 1539 sb_error.SetErrorStringWithFormat ("invalid module"); 1540 } 1541 } 1542 else 1543 { 1544 sb_error.SetErrorStringWithFormat ("invalid target"); 1545 } 1546 return sb_error; 1547 } 1548 1549 1550