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