Target.h revision 5a15e6927b5b3234fb3e688717297ba6b5dd6ad7
1//===-- Target.h ------------------------------------------------*- 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#ifndef liblldb_Target_h_ 11#define liblldb_Target_h_ 12 13// C Includes 14// C++ Includes 15 16// Other libraries and framework includes 17// Project includes 18#include "lldb/lldb-public.h" 19#include "lldb/Breakpoint/BreakpointList.h" 20#include "lldb/Breakpoint/BreakpointLocationCollection.h" 21#include "lldb/Breakpoint/WatchpointList.h" 22#include "lldb/Core/Broadcaster.h" 23#include "lldb/Core/Event.h" 24#include "lldb/Core/ModuleList.h" 25#include "lldb/Core/UserSettingsController.h" 26#include "lldb/Core/SourceManager.h" 27#include "lldb/Expression/ClangPersistentVariables.h" 28#include "lldb/Interpreter/Args.h" 29#include "lldb/Interpreter/NamedOptionValue.h" 30#include "lldb/Symbol/SymbolContext.h" 31#include "lldb/Target/ABI.h" 32#include "lldb/Target/ExecutionContextScope.h" 33#include "lldb/Target/PathMappingList.h" 34#include "lldb/Target/SectionLoadList.h" 35 36namespace lldb_private { 37 38//---------------------------------------------------------------------- 39// TargetInstanceSettings 40//---------------------------------------------------------------------- 41class TargetInstanceSettings : public InstanceSettings 42{ 43public: 44 static OptionEnumValueElement g_dynamic_value_types[]; 45 46 TargetInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); 47 48 TargetInstanceSettings (const TargetInstanceSettings &rhs); 49 50 virtual 51 ~TargetInstanceSettings (); 52 53 TargetInstanceSettings& 54 operator= (const TargetInstanceSettings &rhs); 55 56 void 57 UpdateInstanceSettingsVariable (const ConstString &var_name, 58 const char *index_value, 59 const char *value, 60 const ConstString &instance_name, 61 const SettingEntry &entry, 62 VarSetOperationType op, 63 Error &err, 64 bool pending); 65 66 bool 67 GetInstanceSettingsValue (const SettingEntry &entry, 68 const ConstString &var_name, 69 StringList &value, 70 Error *err); 71 72 lldb::DynamicValueType 73 GetPreferDynamicValue() 74 { 75 return (lldb::DynamicValueType) g_dynamic_value_types[m_prefer_dynamic_value].value; 76 } 77 78 bool 79 GetSkipPrologue() 80 { 81 return m_skip_prologue; 82 } 83 84 PathMappingList & 85 GetSourcePathMap () 86 { 87 return m_source_map; 88 } 89 90 FileSpecList & 91 GetExecutableSearchPaths () 92 { 93 return m_exe_search_paths; 94 } 95 96 const FileSpecList & 97 GetExecutableSearchPaths () const 98 { 99 return m_exe_search_paths; 100 } 101 102 103 uint32_t 104 GetMaximumNumberOfChildrenToDisplay() 105 { 106 return m_max_children_display; 107 } 108 uint32_t 109 GetMaximumSizeOfStringSummary() 110 { 111 return m_max_strlen_length; 112 } 113 114 bool 115 GetBreakpointsConsultPlatformAvoidList () 116 { 117 return m_breakpoints_use_platform_avoid; 118 } 119 120 121 const Args & 122 GetRunArguments () const 123 { 124 return m_run_args; 125 } 126 127 void 128 SetRunArguments (const Args &args) 129 { 130 m_run_args = args; 131 } 132 133 void 134 GetHostEnvironmentIfNeeded (); 135 136 size_t 137 GetEnvironmentAsArgs (Args &env); 138 139 const char * 140 GetStandardInputPath () const 141 { 142 if (m_input_path.empty()) 143 return NULL; 144 return m_input_path.c_str(); 145 } 146 147 void 148 SetStandardInputPath (const char *path) 149 { 150 if (path && path[0]) 151 m_input_path.assign (path); 152 else 153 { 154 // Make sure we deallocate memory in string... 155 std::string tmp; 156 tmp.swap (m_input_path); 157 } 158 } 159 160 const char * 161 GetStandardOutputPath () const 162 { 163 if (m_output_path.empty()) 164 return NULL; 165 return m_output_path.c_str(); 166 } 167 168 void 169 SetStandardOutputPath (const char *path) 170 { 171 if (path && path[0]) 172 m_output_path.assign (path); 173 else 174 { 175 // Make sure we deallocate memory in string... 176 std::string tmp; 177 tmp.swap (m_output_path); 178 } 179 } 180 181 const char * 182 GetStandardErrorPath () const 183 { 184 if (m_error_path.empty()) 185 return NULL; 186 return m_error_path.c_str(); 187 } 188 189 void 190 SetStandardErrorPath (const char *path) 191 { 192 if (path && path[0]) 193 m_error_path.assign (path); 194 else 195 { 196 // Make sure we deallocate memory in string... 197 std::string tmp; 198 tmp.swap (m_error_path); 199 } 200 } 201 202 bool 203 GetDisableASLR () const 204 { 205 return m_disable_aslr; 206 } 207 208 void 209 SetDisableASLR (bool b) 210 { 211 m_disable_aslr = b; 212 } 213 214 bool 215 GetDisableSTDIO () const 216 { 217 return m_disable_stdio; 218 } 219 220 void 221 SetDisableSTDIO (bool b) 222 { 223 m_disable_stdio = b; 224 } 225 226 227protected: 228 229 void 230 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 231 bool pending); 232 233 const ConstString 234 CreateInstanceName (); 235 236 OptionValueFileSpec m_expr_prefix_file; 237 std::string m_expr_prefix_contents; 238 int m_prefer_dynamic_value; 239 OptionValueBoolean m_skip_prologue; 240 PathMappingList m_source_map; 241 FileSpecList m_exe_search_paths; 242 uint32_t m_max_children_display; 243 uint32_t m_max_strlen_length; 244 OptionValueBoolean m_breakpoints_use_platform_avoid; 245 typedef std::map<std::string, std::string> dictionary; 246 Args m_run_args; 247 dictionary m_env_vars; 248 std::string m_input_path; 249 std::string m_output_path; 250 std::string m_error_path; 251 bool m_disable_aslr; 252 bool m_disable_stdio; 253 bool m_inherit_host_env; 254 bool m_got_host_env; 255 256 257}; 258 259//---------------------------------------------------------------------- 260// Target 261//---------------------------------------------------------------------- 262class Target : 263 public std::tr1::enable_shared_from_this<Target>, 264 public Broadcaster, 265 public ExecutionContextScope, 266 public TargetInstanceSettings 267{ 268public: 269 friend class TargetList; 270 271 //------------------------------------------------------------------ 272 /// Broadcaster event bits definitions. 273 //------------------------------------------------------------------ 274 enum 275 { 276 eBroadcastBitBreakpointChanged = (1 << 0), 277 eBroadcastBitModulesLoaded = (1 << 1), 278 eBroadcastBitModulesUnloaded = (1 << 2) 279 }; 280 281 // These two functions fill out the Broadcaster interface: 282 283 static ConstString &GetStaticBroadcasterClass (); 284 285 virtual ConstString &GetBroadcasterClass() const 286 { 287 return GetStaticBroadcasterClass(); 288 } 289 290 // This event data class is for use by the TargetList to broadcast new target notifications. 291 class TargetEventData : public EventData 292 { 293 public: 294 295 static const ConstString & 296 GetFlavorString (); 297 298 virtual const ConstString & 299 GetFlavor () const; 300 301 TargetEventData (const lldb::TargetSP &new_target_sp); 302 303 lldb::TargetSP & 304 GetTarget() 305 { 306 return m_target_sp; 307 } 308 309 virtual 310 ~TargetEventData(); 311 312 virtual void 313 Dump (Stream *s) const; 314 315 static const lldb::TargetSP 316 GetTargetFromEvent (const lldb::EventSP &event_sp); 317 318 static const TargetEventData * 319 GetEventDataFromEvent (const Event *event_sp); 320 321 private: 322 lldb::TargetSP m_target_sp; 323 324 DISALLOW_COPY_AND_ASSIGN (TargetEventData); 325 }; 326 327 static void 328 SettingsInitialize (); 329 330 static void 331 SettingsTerminate (); 332 333 static lldb::UserSettingsControllerSP & 334 GetSettingsController (); 335 336 static FileSpecList 337 GetDefaultExecutableSearchPaths (); 338 339 static ArchSpec 340 GetDefaultArchitecture (); 341 342 static void 343 SetDefaultArchitecture (const ArchSpec &arch); 344 345 void 346 UpdateInstanceName (); 347 348 lldb::ModuleSP 349 GetSharedModule (const FileSpec& file_spec, 350 const ArchSpec& arch, 351 const lldb_private::UUID *uuid = NULL, 352 const ConstString *object_name = NULL, 353 off_t object_offset = 0, 354 Error *error_ptr = NULL); 355private: 356 //------------------------------------------------------------------ 357 /// Construct with optional file and arch. 358 /// 359 /// This member is private. Clients must use 360 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 361 /// so all targets can be tracked from the central target list. 362 /// 363 /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 364 //------------------------------------------------------------------ 365 Target (Debugger &debugger, 366 const ArchSpec &target_arch, 367 const lldb::PlatformSP &platform_sp); 368 369 // Helper function. 370 bool 371 ProcessIsValid (); 372 373public: 374 ~Target(); 375 376 Mutex & 377 GetAPIMutex () 378 { 379 return m_mutex; 380 } 381 382 void 383 DeleteCurrentProcess (); 384 385 //------------------------------------------------------------------ 386 /// Dump a description of this object to a Stream. 387 /// 388 /// Dump a description of the contents of this object to the 389 /// supplied stream \a s. The dumped content will be only what has 390 /// been loaded or parsed up to this point at which this function 391 /// is called, so this is a good way to see what has been parsed 392 /// in a target. 393 /// 394 /// @param[in] s 395 /// The stream to which to dump the object descripton. 396 //------------------------------------------------------------------ 397 void 398 Dump (Stream *s, lldb::DescriptionLevel description_level); 399 400 const lldb::ProcessSP & 401 CreateProcess (Listener &listener, 402 const char *plugin_name, 403 const FileSpec *crash_file); 404 405 const lldb::ProcessSP & 406 GetProcessSP () const; 407 408 void 409 Destroy(); 410 411 //------------------------------------------------------------------ 412 // This part handles the breakpoints. 413 //------------------------------------------------------------------ 414 415 BreakpointList & 416 GetBreakpointList(bool internal = false); 417 418 const BreakpointList & 419 GetBreakpointList(bool internal = false) const; 420 421 lldb::BreakpointSP 422 GetLastCreatedBreakpoint () 423 { 424 return m_last_created_breakpoint; 425 } 426 427 lldb::BreakpointSP 428 GetBreakpointByID (lldb::break_id_t break_id); 429 430 // Use this to create a file and line breakpoint to a given module or all module it is NULL 431 lldb::BreakpointSP 432 CreateBreakpoint (const FileSpecList *containingModules, 433 const FileSpec &file, 434 uint32_t line_no, 435 bool check_inlines, 436 bool internal = false); 437 438 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list: 439 lldb::BreakpointSP 440 CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 441 const FileSpecList *source_file_list, 442 RegularExpression &source_regex, 443 bool internal = false); 444 445 // Use this to create a breakpoint from a load address 446 lldb::BreakpointSP 447 CreateBreakpoint (lldb::addr_t load_addr, 448 bool internal = false); 449 450 // Use this to create Address breakpoints: 451 lldb::BreakpointSP 452 CreateBreakpoint (Address &addr, 453 bool internal = false); 454 455 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL 456 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 457 // setting, else we use the values passed in 458 lldb::BreakpointSP 459 CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 460 const FileSpecList *containingSourceFiles, 461 RegularExpression &func_regexp, 462 bool internal = false, 463 LazyBool skip_prologue = eLazyBoolCalculate); 464 465 // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL 466 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 467 // setting, else we use the values passed in 468 lldb::BreakpointSP 469 CreateBreakpoint (const FileSpecList *containingModules, 470 const FileSpecList *containingSourceFiles, 471 const char *func_name, 472 uint32_t func_name_type_mask, 473 bool internal = false, 474 LazyBool skip_prologue = eLazyBoolCalculate); 475 476 // Use this to create a general breakpoint: 477 lldb::BreakpointSP 478 CreateBreakpoint (lldb::SearchFilterSP &filter_sp, 479 lldb::BreakpointResolverSP &resolver_sp, 480 bool internal = false); 481 482 // Use this to create a watchpoint: 483 lldb::WatchpointSP 484 CreateWatchpoint (lldb::addr_t addr, 485 size_t size, 486 uint32_t type); 487 488 lldb::WatchpointSP 489 GetLastCreatedWatchpoint () 490 { 491 return m_last_created_watchpoint; 492 } 493 494 WatchpointList & 495 GetWatchpointList() 496 { 497 return m_watchpoint_list; 498 } 499 500 void 501 RemoveAllBreakpoints (bool internal_also = false); 502 503 void 504 DisableAllBreakpoints (bool internal_also = false); 505 506 void 507 EnableAllBreakpoints (bool internal_also = false); 508 509 bool 510 DisableBreakpointByID (lldb::break_id_t break_id); 511 512 bool 513 EnableBreakpointByID (lldb::break_id_t break_id); 514 515 bool 516 RemoveBreakpointByID (lldb::break_id_t break_id); 517 518 // The flag 'end_to_end', default to true, signifies that the operation is 519 // performed end to end, for both the debugger and the debuggee. 520 521 bool 522 RemoveAllWatchpoints (bool end_to_end = true); 523 524 bool 525 DisableAllWatchpoints (bool end_to_end = true); 526 527 bool 528 EnableAllWatchpoints (bool end_to_end = true); 529 530 bool 531 IgnoreAllWatchpoints (uint32_t ignore_count); 532 533 bool 534 DisableWatchpointByID (lldb::watch_id_t watch_id); 535 536 bool 537 EnableWatchpointByID (lldb::watch_id_t watch_id); 538 539 bool 540 RemoveWatchpointByID (lldb::watch_id_t watch_id); 541 542 bool 543 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); 544 545 void 546 ModulesDidLoad (ModuleList &module_list); 547 548 void 549 ModulesDidUnload (ModuleList &module_list); 550 551 552 //------------------------------------------------------------------ 553 /// Get \a load_addr as a callable code load address for this target 554 /// 555 /// Take \a load_addr and potentially add any address bits that are 556 /// needed to make the address callable. For ARM this can set bit 557 /// zero (if it already isn't) if \a load_addr is a thumb function. 558 /// If \a addr_class is set to eAddressClassInvalid, then the address 559 /// adjustment will always happen. If it is set to an address class 560 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 561 /// returned. 562 //------------------------------------------------------------------ 563 lldb::addr_t 564 GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 565 566 //------------------------------------------------------------------ 567 /// Get \a load_addr as an opcode for this target. 568 /// 569 /// Take \a load_addr and potentially strip any address bits that are 570 /// needed to make the address point to an opcode. For ARM this can 571 /// clear bit zero (if it already isn't) if \a load_addr is a 572 /// thumb function and load_addr is in code. 573 /// If \a addr_class is set to eAddressClassInvalid, then the address 574 /// adjustment will always happen. If it is set to an address class 575 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 576 /// returned. 577 //------------------------------------------------------------------ 578 lldb::addr_t 579 GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 580 581protected: 582 void 583 ModuleAdded (lldb::ModuleSP &module_sp); 584 585 void 586 ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp); 587 588public: 589 //------------------------------------------------------------------ 590 /// Gets the module for the main executable. 591 /// 592 /// Each process has a notion of a main executable that is the file 593 /// that will be executed or attached to. Executable files can have 594 /// dependent modules that are discovered from the object files, or 595 /// discovered at runtime as things are dynamically loaded. 596 /// 597 /// @return 598 /// The shared pointer to the executable module which can 599 /// contains a NULL Module object if no executable has been 600 /// set. 601 /// 602 /// @see DynamicLoader 603 /// @see ObjectFile::GetDependentModules (FileSpecList&) 604 /// @see Process::SetExecutableModule(lldb::ModuleSP&) 605 //------------------------------------------------------------------ 606 lldb::ModuleSP 607 GetExecutableModule (); 608 609 Module* 610 GetExecutableModulePointer (); 611 612 //------------------------------------------------------------------ 613 /// Set the main executable module. 614 /// 615 /// Each process has a notion of a main executable that is the file 616 /// that will be executed or attached to. Executable files can have 617 /// dependent modules that are discovered from the object files, or 618 /// discovered at runtime as things are dynamically loaded. 619 /// 620 /// Setting the executable causes any of the current dependant 621 /// image information to be cleared and replaced with the static 622 /// dependent image information found by calling 623 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 624 /// executable and any modules on which it depends. Calling 625 /// Process::GetImages() will return the newly found images that 626 /// were obtained from all of the object files. 627 /// 628 /// @param[in] module_sp 629 /// A shared pointer reference to the module that will become 630 /// the main executable for this process. 631 /// 632 /// @param[in] get_dependent_files 633 /// If \b true then ask the object files to track down any 634 /// known dependent files. 635 /// 636 /// @see ObjectFile::GetDependentModules (FileSpecList&) 637 /// @see Process::GetImages() 638 //------------------------------------------------------------------ 639 void 640 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); 641 642 //------------------------------------------------------------------ 643 /// Get accessor for the images for this process. 644 /// 645 /// Each process has a notion of a main executable that is the file 646 /// that will be executed or attached to. Executable files can have 647 /// dependent modules that are discovered from the object files, or 648 /// discovered at runtime as things are dynamically loaded. After 649 /// a main executable has been set, the images will contain a list 650 /// of all the files that the executable depends upon as far as the 651 /// object files know. These images will usually contain valid file 652 /// virtual addresses only. When the process is launched or attached 653 /// to, the DynamicLoader plug-in will discover where these images 654 /// were loaded in memory and will resolve the load virtual 655 /// addresses is each image, and also in images that are loaded by 656 /// code. 657 /// 658 /// @return 659 /// A list of Module objects in a module list. 660 //------------------------------------------------------------------ 661 ModuleList& 662 GetImages () 663 { 664 return m_images; 665 } 666 667 const ModuleList& 668 GetImages () const 669 { 670 return m_images; 671 } 672 673 674 //------------------------------------------------------------------ 675 /// Return whether this FileSpec corresponds to a module that should be considered for general searches. 676 /// 677 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 678 /// and any module that returns \b true will not be searched. Note the 679 /// SearchFilterForNonModuleSpecificSearches is the search filter that 680 /// gets used in the CreateBreakpoint calls when no modules is provided. 681 /// 682 /// The target call at present just consults the Platform's call of the 683 /// same name. 684 /// 685 /// @param[in] module_sp 686 /// A shared pointer reference to the module that checked. 687 /// 688 /// @return \b true if the module should be excluded, \b false otherwise. 689 //------------------------------------------------------------------ 690 bool 691 ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec); 692 693 //------------------------------------------------------------------ 694 /// Return whether this module should be considered for general searches. 695 /// 696 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 697 /// and any module that returns \b true will not be searched. Note the 698 /// SearchFilterForNonModuleSpecificSearches is the search filter that 699 /// gets used in the CreateBreakpoint calls when no modules is provided. 700 /// 701 /// The target call at present just consults the Platform's call of the 702 /// same name. 703 /// 704 /// FIXME: When we get time we should add a way for the user to set modules that they 705 /// don't want searched, in addition to or instead of the platform ones. 706 /// 707 /// @param[in] module_sp 708 /// A shared pointer reference to the module that checked. 709 /// 710 /// @return \b true if the module should be excluded, \b false otherwise. 711 //------------------------------------------------------------------ 712 bool 713 ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp); 714 715 ArchSpec & 716 GetArchitecture () 717 { 718 return m_arch; 719 } 720 721 const ArchSpec & 722 GetArchitecture () const 723 { 724 return m_arch; 725 } 726 727 //------------------------------------------------------------------ 728 /// Set the architecture for this target. 729 /// 730 /// If the current target has no Images read in, then this just sets the architecture, which will 731 /// be used to select the architecture of the ExecutableModule when that is set. 732 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different 733 /// architecture from the currently selected one will reset the ExecutableModule to that slice 734 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not 735 /// contain a fork of this architecture, then this code will return false, and the architecture 736 /// won't be changed. 737 /// If the input arch_spec is the same as the already set architecture, this is a no-op. 738 /// 739 /// @param[in] arch_spec 740 /// The new architecture. 741 /// 742 /// @return 743 /// \b true if the architecture was successfully set, \bfalse otherwise. 744 //------------------------------------------------------------------ 745 bool 746 SetArchitecture (const ArchSpec &arch_spec); 747 748 Debugger & 749 GetDebugger () 750 { 751 return m_debugger; 752 } 753 754 size_t 755 ReadMemoryFromFileCache (const Address& addr, 756 void *dst, 757 size_t dst_len, 758 Error &error); 759 760 // Reading memory through the target allows us to skip going to the process 761 // for reading memory if possible and it allows us to try and read from 762 // any constant sections in our object files on disk. If you always want 763 // live program memory, read straight from the process. If you possibly 764 // want to read from const sections in object files, read from the target. 765 // This version of ReadMemory will try and read memory from the process 766 // if the process is alive. The order is: 767 // 1 - if (prefer_file_cache == true) then read from object file cache 768 // 2 - if there is a valid process, try and read from its memory 769 // 3 - if (prefer_file_cache == false) then read from object file cache 770 size_t 771 ReadMemory (const Address& addr, 772 bool prefer_file_cache, 773 void *dst, 774 size_t dst_len, 775 Error &error, 776 lldb::addr_t *load_addr_ptr = NULL); 777 778 size_t 779 ReadScalarIntegerFromMemory (const Address& addr, 780 bool prefer_file_cache, 781 uint32_t byte_size, 782 bool is_signed, 783 Scalar &scalar, 784 Error &error); 785 786 uint64_t 787 ReadUnsignedIntegerFromMemory (const Address& addr, 788 bool prefer_file_cache, 789 size_t integer_byte_size, 790 uint64_t fail_value, 791 Error &error); 792 793 bool 794 ReadPointerFromMemory (const Address& addr, 795 bool prefer_file_cache, 796 Error &error, 797 Address &pointer_addr); 798 799 SectionLoadList& 800 GetSectionLoadList() 801 { 802 return m_section_load_list; 803 } 804 805 const SectionLoadList& 806 GetSectionLoadList() const 807 { 808 return m_section_load_list; 809 } 810 811 812 //------------------------------------------------------------------ 813 /// Load a module in this target by at the section file addresses 814 /// with an optional constant slide applied to each section. 815 /// 816 /// This function will load all top level sections at their file 817 /// addresses and apply an optional constant slide amount to each 818 /// section. This can be used to easily load a module at the same 819 /// addresses that are contained in the object file (trust that 820 /// the addresses in an object file are the correct load addresses). 821 /// 822 /// @param[in] module 823 /// The module to load. 824 /// 825 /// @param[in] slide 826 /// A constant slide to add to each file address as each section 827 /// is being loaded. 828 /// 829 /// @return 830 /// \b true if loading the module at the specified address 831 /// causes a section to be loaded when it previously wasn't, or 832 /// if a section changes load address. Returns \b false if 833 /// the sections were all already loaded at these addresses. 834 //------------------------------------------------------------------ 835 bool 836 LoadModuleWithSlide (Module *module, lldb::addr_t slide); 837 838 static Target * 839 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 840 const SymbolContext *sc_ptr); 841 842 //------------------------------------------------------------------ 843 // lldb::ExecutionContextScope pure virtual functions 844 //------------------------------------------------------------------ 845 virtual Target * 846 CalculateTarget (); 847 848 virtual Process * 849 CalculateProcess (); 850 851 virtual Thread * 852 CalculateThread (); 853 854 virtual StackFrame * 855 CalculateStackFrame (); 856 857 virtual void 858 CalculateExecutionContext (ExecutionContext &exe_ctx); 859 860 PathMappingList & 861 GetImageSearchPathList (); 862 863 ClangASTContext * 864 GetScratchClangASTContext(bool create_on_demand=true); 865 866 ClangASTImporter * 867 GetClangASTImporter(); 868 869 const char * 870 GetExpressionPrefixContentsAsCString (); 871 872 // Since expressions results can persist beyond the lifetime of a process, 873 // and the const expression results are available after a process is gone, 874 // we provide a way for expressions to be evaluated from the Target itself. 875 // If an expression is going to be run, then it should have a frame filled 876 // in in th execution context. 877 ExecutionResults 878 EvaluateExpression (const char *expression, 879 StackFrame *frame, 880 lldb_private::ExecutionPolicy execution_policy, 881 bool coerce_to_id, 882 bool unwind_on_error, 883 bool keep_in_memory, 884 lldb::DynamicValueType use_dynamic, 885 lldb::ValueObjectSP &result_valobj_sp); 886 887 ClangPersistentVariables & 888 GetPersistentVariables() 889 { 890 return m_persistent_variables; 891 } 892 893 //------------------------------------------------------------------ 894 // Target Stop Hooks 895 //------------------------------------------------------------------ 896 class StopHook : public UserID 897 { 898 public: 899 ~StopHook (); 900 901 StopHook (const StopHook &rhs); 902 903 StringList * 904 GetCommandPointer () 905 { 906 return &m_commands; 907 } 908 909 const StringList & 910 GetCommands() 911 { 912 return m_commands; 913 } 914 915 lldb::TargetSP & 916 GetTarget() 917 { 918 return m_target_sp; 919 } 920 921 void 922 SetCommands (StringList &in_commands) 923 { 924 m_commands = in_commands; 925 } 926 927 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done. 928 void 929 SetSpecifier (SymbolContextSpecifier *specifier) 930 { 931 m_specifier_sp.reset (specifier); 932 } 933 934 SymbolContextSpecifier * 935 GetSpecifier () 936 { 937 return m_specifier_sp.get(); 938 } 939 940 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done. 941 void 942 SetThreadSpecifier (ThreadSpec *specifier); 943 944 ThreadSpec * 945 GetThreadSpecifier() 946 { 947 return m_thread_spec_ap.get(); 948 } 949 950 bool 951 IsActive() 952 { 953 return m_active; 954 } 955 956 void 957 SetIsActive (bool is_active) 958 { 959 m_active = is_active; 960 } 961 962 void 963 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 964 965 private: 966 lldb::TargetSP m_target_sp; 967 StringList m_commands; 968 lldb::SymbolContextSpecifierSP m_specifier_sp; 969 std::auto_ptr<ThreadSpec> m_thread_spec_ap; 970 bool m_active; 971 972 // Use AddStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands, 973 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.) 974 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid); 975 friend class Target; 976 }; 977 typedef SHARED_PTR(StopHook) StopHookSP; 978 979 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook. 980 // Returns the id of the new hook. 981 lldb::user_id_t 982 AddStopHook (StopHookSP &new_hook); 983 984 void 985 RunStopHooks (); 986 987 size_t 988 GetStopHookSize(); 989 990 bool 991 SetSuppresStopHooks (bool suppress) 992 { 993 bool old_value = m_suppress_stop_hooks; 994 m_suppress_stop_hooks = suppress; 995 return old_value; 996 } 997 998 bool 999 GetSuppressStopHooks () 1000 { 1001 return m_suppress_stop_hooks; 1002 } 1003 1004// StopHookSP & 1005// GetStopHookByIndex (size_t index); 1006// 1007 bool 1008 RemoveStopHookByID (lldb::user_id_t uid); 1009 1010 void 1011 RemoveAllStopHooks (); 1012 1013 StopHookSP 1014 GetStopHookByID (lldb::user_id_t uid); 1015 1016 bool 1017 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state); 1018 1019 void 1020 SetAllStopHooksActiveState (bool active_state); 1021 1022 size_t GetNumStopHooks () const 1023 { 1024 return m_stop_hooks.size(); 1025 } 1026 1027 StopHookSP 1028 GetStopHookAtIndex (size_t index) 1029 { 1030 if (index >= GetNumStopHooks()) 1031 return StopHookSP(); 1032 StopHookCollection::iterator pos = m_stop_hooks.begin(); 1033 1034 while (index > 0) 1035 { 1036 pos++; 1037 index--; 1038 } 1039 return (*pos).second; 1040 } 1041 1042 lldb::PlatformSP 1043 GetPlatform () 1044 { 1045 return m_platform_sp; 1046 } 1047 1048 SourceManager & 1049 GetSourceManager () 1050 { 1051 return m_source_manager; 1052 } 1053 1054 //------------------------------------------------------------------ 1055 // Target::SettingsController 1056 //------------------------------------------------------------------ 1057 class SettingsController : public UserSettingsController 1058 { 1059 public: 1060 SettingsController (); 1061 1062 virtual 1063 ~SettingsController (); 1064 1065 bool 1066 SetGlobalVariable (const ConstString &var_name, 1067 const char *index_value, 1068 const char *value, 1069 const SettingEntry &entry, 1070 const VarSetOperationType op, 1071 Error&err); 1072 1073 bool 1074 GetGlobalVariable (const ConstString &var_name, 1075 StringList &value, 1076 Error &err); 1077 1078 static SettingEntry global_settings_table[]; 1079 static SettingEntry instance_settings_table[]; 1080 1081 ArchSpec & 1082 GetArchitecture () 1083 { 1084 return m_default_architecture; 1085 } 1086 protected: 1087 1088 lldb::InstanceSettingsSP 1089 CreateInstanceSettings (const char *instance_name); 1090 1091 private: 1092 1093 // Class-wide settings. 1094 ArchSpec m_default_architecture; 1095 1096 DISALLOW_COPY_AND_ASSIGN (SettingsController); 1097 }; 1098 1099 1100protected: 1101 //------------------------------------------------------------------ 1102 // Member variables. 1103 //------------------------------------------------------------------ 1104 Debugger & m_debugger; 1105 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1106 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe 1107 ArchSpec m_arch; 1108 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). 1109 SectionLoadList m_section_load_list; 1110 BreakpointList m_breakpoint_list; 1111 BreakpointList m_internal_breakpoint_list; 1112 lldb::BreakpointSP m_last_created_breakpoint; 1113 WatchpointList m_watchpoint_list; 1114 lldb::WatchpointSP m_last_created_watchpoint; 1115 // We want to tightly control the process destruction process so 1116 // we can correctly tear down everything that we need to, so the only 1117 // class that knows about the process lifespan is this target class. 1118 lldb::ProcessSP m_process_sp; 1119 lldb::SearchFilterSP m_search_filter_sp; 1120 PathMappingList m_image_search_paths; 1121 std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap; 1122 std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap; 1123 std::auto_ptr<ClangASTImporter> m_ast_importer_ap; 1124 ClangPersistentVariables m_persistent_variables; ///< These are the persistent variables associated with this process for the expression parser. 1125 1126 SourceManager m_source_manager; 1127 1128 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1129 StopHookCollection m_stop_hooks; 1130 lldb::user_id_t m_stop_hook_next_id; 1131 bool m_suppress_stop_hooks; 1132 1133 //------------------------------------------------------------------ 1134 // Methods. 1135 //------------------------------------------------------------------ 1136 lldb::SearchFilterSP 1137 GetSearchFilterForModule (const FileSpec *containingModule); 1138 1139 lldb::SearchFilterSP 1140 GetSearchFilterForModuleList (const FileSpecList *containingModuleList); 1141 1142 lldb::SearchFilterSP 1143 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); 1144 1145 1146 static void 1147 ImageSearchPathsChanged (const PathMappingList &path_list, 1148 void *baton); 1149 1150private: 1151 DISALLOW_COPY_AND_ASSIGN (Target); 1152}; 1153 1154} // namespace lldb_private 1155 1156#endif // liblldb_Target_h_ 1157