Target.h revision 598df88bd6fc33c6fb330bc859bdc277795501f3
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_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 ModuleSpec &module_spec, 350 Error *error_ptr = NULL); 351private: 352 //------------------------------------------------------------------ 353 /// Construct with optional file and arch. 354 /// 355 /// This member is private. Clients must use 356 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 357 /// so all targets can be tracked from the central target list. 358 /// 359 /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 360 //------------------------------------------------------------------ 361 Target (Debugger &debugger, 362 const ArchSpec &target_arch, 363 const lldb::PlatformSP &platform_sp); 364 365 // Helper function. 366 bool 367 ProcessIsValid (); 368 369public: 370 ~Target(); 371 372 Mutex & 373 GetAPIMutex () 374 { 375 return m_mutex; 376 } 377 378 void 379 DeleteCurrentProcess (); 380 381 //------------------------------------------------------------------ 382 /// Dump a description of this object to a Stream. 383 /// 384 /// Dump a description of the contents of this object to the 385 /// supplied stream \a s. The dumped content will be only what has 386 /// been loaded or parsed up to this point at which this function 387 /// is called, so this is a good way to see what has been parsed 388 /// in a target. 389 /// 390 /// @param[in] s 391 /// The stream to which to dump the object descripton. 392 //------------------------------------------------------------------ 393 void 394 Dump (Stream *s, lldb::DescriptionLevel description_level); 395 396 const lldb::ProcessSP & 397 CreateProcess (Listener &listener, 398 const char *plugin_name, 399 const FileSpec *crash_file); 400 401 const lldb::ProcessSP & 402 GetProcessSP () const; 403 404 void 405 Destroy(); 406 407 //------------------------------------------------------------------ 408 // This part handles the breakpoints. 409 //------------------------------------------------------------------ 410 411 BreakpointList & 412 GetBreakpointList(bool internal = false); 413 414 const BreakpointList & 415 GetBreakpointList(bool internal = false) const; 416 417 lldb::BreakpointSP 418 GetLastCreatedBreakpoint () 419 { 420 return m_last_created_breakpoint; 421 } 422 423 lldb::BreakpointSP 424 GetBreakpointByID (lldb::break_id_t break_id); 425 426 // Use this to create a file and line breakpoint to a given module or all module it is NULL 427 lldb::BreakpointSP 428 CreateBreakpoint (const FileSpecList *containingModules, 429 const FileSpec &file, 430 uint32_t line_no, 431 bool check_inlines, 432 bool internal = false); 433 434 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list: 435 lldb::BreakpointSP 436 CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 437 const FileSpecList *source_file_list, 438 RegularExpression &source_regex, 439 bool internal = false); 440 441 // Use this to create a breakpoint from a load address 442 lldb::BreakpointSP 443 CreateBreakpoint (lldb::addr_t load_addr, 444 bool internal = false); 445 446 // Use this to create Address breakpoints: 447 lldb::BreakpointSP 448 CreateBreakpoint (Address &addr, 449 bool internal = false); 450 451 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL 452 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 453 // setting, else we use the values passed in 454 lldb::BreakpointSP 455 CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 456 const FileSpecList *containingSourceFiles, 457 RegularExpression &func_regexp, 458 bool internal = false, 459 LazyBool skip_prologue = eLazyBoolCalculate); 460 461 // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL 462 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 463 // setting, else we use the values passed in 464 lldb::BreakpointSP 465 CreateBreakpoint (const FileSpecList *containingModules, 466 const FileSpecList *containingSourceFiles, 467 const char *func_name, 468 uint32_t func_name_type_mask, 469 bool internal = false, 470 LazyBool skip_prologue = eLazyBoolCalculate); 471 472 lldb::BreakpointSP 473 CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal = false); 474 475 // This is the same as the func_name breakpoint except that you can specify a vector of names. This is cheaper 476 // than a regular expression breakpoint in the case where you just want to set a breakpoint on a set of names 477 // you already know. 478 lldb::BreakpointSP 479 CreateBreakpoint (const FileSpecList *containingModules, 480 const FileSpecList *containingSourceFiles, 481 const char *func_names[], 482 size_t num_names, 483 uint32_t func_name_type_mask, 484 bool internal = false, 485 LazyBool skip_prologue = eLazyBoolCalculate); 486 487 lldb::BreakpointSP 488 CreateBreakpoint (const FileSpecList *containingModules, 489 const FileSpecList *containingSourceFiles, 490 std::vector<std::string> func_names, 491 uint32_t func_name_type_mask, 492 bool internal = false, 493 LazyBool skip_prologue = eLazyBoolCalculate); 494 495 496 // Use this to create a general breakpoint: 497 lldb::BreakpointSP 498 CreateBreakpoint (lldb::SearchFilterSP &filter_sp, 499 lldb::BreakpointResolverSP &resolver_sp, 500 bool internal = false); 501 502 // Use this to create a watchpoint: 503 lldb::WatchpointSP 504 CreateWatchpoint (lldb::addr_t addr, 505 size_t size, 506 uint32_t type); 507 508 lldb::WatchpointSP 509 GetLastCreatedWatchpoint () 510 { 511 return m_last_created_watchpoint; 512 } 513 514 WatchpointList & 515 GetWatchpointList() 516 { 517 return m_watchpoint_list; 518 } 519 520 void 521 RemoveAllBreakpoints (bool internal_also = false); 522 523 void 524 DisableAllBreakpoints (bool internal_also = false); 525 526 void 527 EnableAllBreakpoints (bool internal_also = false); 528 529 bool 530 DisableBreakpointByID (lldb::break_id_t break_id); 531 532 bool 533 EnableBreakpointByID (lldb::break_id_t break_id); 534 535 bool 536 RemoveBreakpointByID (lldb::break_id_t break_id); 537 538 // The flag 'end_to_end', default to true, signifies that the operation is 539 // performed end to end, for both the debugger and the debuggee. 540 541 bool 542 RemoveAllWatchpoints (bool end_to_end = true); 543 544 bool 545 DisableAllWatchpoints (bool end_to_end = true); 546 547 bool 548 EnableAllWatchpoints (bool end_to_end = true); 549 550 bool 551 ClearAllWatchpointHitCounts (); 552 553 bool 554 IgnoreAllWatchpoints (uint32_t ignore_count); 555 556 bool 557 DisableWatchpointByID (lldb::watch_id_t watch_id); 558 559 bool 560 EnableWatchpointByID (lldb::watch_id_t watch_id); 561 562 bool 563 RemoveWatchpointByID (lldb::watch_id_t watch_id); 564 565 bool 566 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); 567 568 void 569 ModulesDidLoad (ModuleList &module_list); 570 571 void 572 ModulesDidUnload (ModuleList &module_list); 573 574 575 //------------------------------------------------------------------ 576 /// Get \a load_addr as a callable code load address for this target 577 /// 578 /// Take \a load_addr and potentially add any address bits that are 579 /// needed to make the address callable. For ARM this can set bit 580 /// zero (if it already isn't) if \a load_addr is a thumb function. 581 /// If \a addr_class is set to eAddressClassInvalid, then the address 582 /// adjustment will always happen. If it is set to an address class 583 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 584 /// returned. 585 //------------------------------------------------------------------ 586 lldb::addr_t 587 GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 588 589 //------------------------------------------------------------------ 590 /// Get \a load_addr as an opcode for this target. 591 /// 592 /// Take \a load_addr and potentially strip any address bits that are 593 /// needed to make the address point to an opcode. For ARM this can 594 /// clear bit zero (if it already isn't) if \a load_addr is a 595 /// thumb function and load_addr is in code. 596 /// If \a addr_class is set to eAddressClassInvalid, then the address 597 /// adjustment will always happen. If it is set to an address class 598 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 599 /// returned. 600 //------------------------------------------------------------------ 601 lldb::addr_t 602 GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 603 604protected: 605 void 606 ModuleAdded (lldb::ModuleSP &module_sp); 607 608 void 609 ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp); 610 611public: 612 //------------------------------------------------------------------ 613 /// Gets the module for the main executable. 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 /// @return 621 /// The shared pointer to the executable module which can 622 /// contains a NULL Module object if no executable has been 623 /// set. 624 /// 625 /// @see DynamicLoader 626 /// @see ObjectFile::GetDependentModules (FileSpecList&) 627 /// @see Process::SetExecutableModule(lldb::ModuleSP&) 628 //------------------------------------------------------------------ 629 lldb::ModuleSP 630 GetExecutableModule (); 631 632 Module* 633 GetExecutableModulePointer (); 634 635 //------------------------------------------------------------------ 636 /// Set the main executable module. 637 /// 638 /// Each process has a notion of a main executable that is the file 639 /// that will be executed or attached to. Executable files can have 640 /// dependent modules that are discovered from the object files, or 641 /// discovered at runtime as things are dynamically loaded. 642 /// 643 /// Setting the executable causes any of the current dependant 644 /// image information to be cleared and replaced with the static 645 /// dependent image information found by calling 646 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 647 /// executable and any modules on which it depends. Calling 648 /// Process::GetImages() will return the newly found images that 649 /// were obtained from all of the object files. 650 /// 651 /// @param[in] module_sp 652 /// A shared pointer reference to the module that will become 653 /// the main executable for this process. 654 /// 655 /// @param[in] get_dependent_files 656 /// If \b true then ask the object files to track down any 657 /// known dependent files. 658 /// 659 /// @see ObjectFile::GetDependentModules (FileSpecList&) 660 /// @see Process::GetImages() 661 //------------------------------------------------------------------ 662 void 663 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); 664 665 //------------------------------------------------------------------ 666 /// Get accessor for the images for this process. 667 /// 668 /// Each process has a notion of a main executable that is the file 669 /// that will be executed or attached to. Executable files can have 670 /// dependent modules that are discovered from the object files, or 671 /// discovered at runtime as things are dynamically loaded. After 672 /// a main executable has been set, the images will contain a list 673 /// of all the files that the executable depends upon as far as the 674 /// object files know. These images will usually contain valid file 675 /// virtual addresses only. When the process is launched or attached 676 /// to, the DynamicLoader plug-in will discover where these images 677 /// were loaded in memory and will resolve the load virtual 678 /// addresses is each image, and also in images that are loaded by 679 /// code. 680 /// 681 /// @return 682 /// A list of Module objects in a module list. 683 //------------------------------------------------------------------ 684 ModuleList& 685 GetImages () 686 { 687 return m_images; 688 } 689 690 const ModuleList& 691 GetImages () const 692 { 693 return m_images; 694 } 695 696 697 //------------------------------------------------------------------ 698 /// Return whether this FileSpec corresponds to a module that should be considered for general searches. 699 /// 700 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 701 /// and any module that returns \b true will not be searched. Note the 702 /// SearchFilterForNonModuleSpecificSearches is the search filter that 703 /// gets used in the CreateBreakpoint calls when no modules is provided. 704 /// 705 /// The target call at present just consults the Platform's call of the 706 /// same name. 707 /// 708 /// @param[in] module_sp 709 /// A shared pointer reference to the module that checked. 710 /// 711 /// @return \b true if the module should be excluded, \b false otherwise. 712 //------------------------------------------------------------------ 713 bool 714 ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec); 715 716 //------------------------------------------------------------------ 717 /// Return whether this module should be considered for general searches. 718 /// 719 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 720 /// and any module that returns \b true will not be searched. Note the 721 /// SearchFilterForNonModuleSpecificSearches is the search filter that 722 /// gets used in the CreateBreakpoint calls when no modules is provided. 723 /// 724 /// The target call at present just consults the Platform's call of the 725 /// same name. 726 /// 727 /// FIXME: When we get time we should add a way for the user to set modules that they 728 /// don't want searched, in addition to or instead of the platform ones. 729 /// 730 /// @param[in] module_sp 731 /// A shared pointer reference to the module that checked. 732 /// 733 /// @return \b true if the module should be excluded, \b false otherwise. 734 //------------------------------------------------------------------ 735 bool 736 ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp); 737 738 ArchSpec & 739 GetArchitecture () 740 { 741 return m_arch; 742 } 743 744 const ArchSpec & 745 GetArchitecture () const 746 { 747 return m_arch; 748 } 749 750 //------------------------------------------------------------------ 751 /// Set the architecture for this target. 752 /// 753 /// If the current target has no Images read in, then this just sets the architecture, which will 754 /// be used to select the architecture of the ExecutableModule when that is set. 755 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different 756 /// architecture from the currently selected one will reset the ExecutableModule to that slice 757 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not 758 /// contain a fork of this architecture, then this code will return false, and the architecture 759 /// won't be changed. 760 /// If the input arch_spec is the same as the already set architecture, this is a no-op. 761 /// 762 /// @param[in] arch_spec 763 /// The new architecture. 764 /// 765 /// @return 766 /// \b true if the architecture was successfully set, \bfalse otherwise. 767 //------------------------------------------------------------------ 768 bool 769 SetArchitecture (const ArchSpec &arch_spec); 770 771 Debugger & 772 GetDebugger () 773 { 774 return m_debugger; 775 } 776 777 size_t 778 ReadMemoryFromFileCache (const Address& addr, 779 void *dst, 780 size_t dst_len, 781 Error &error); 782 783 // Reading memory through the target allows us to skip going to the process 784 // for reading memory if possible and it allows us to try and read from 785 // any constant sections in our object files on disk. If you always want 786 // live program memory, read straight from the process. If you possibly 787 // want to read from const sections in object files, read from the target. 788 // This version of ReadMemory will try and read memory from the process 789 // if the process is alive. The order is: 790 // 1 - if (prefer_file_cache == true) then read from object file cache 791 // 2 - if there is a valid process, try and read from its memory 792 // 3 - if (prefer_file_cache == false) then read from object file cache 793 size_t 794 ReadMemory (const Address& addr, 795 bool prefer_file_cache, 796 void *dst, 797 size_t dst_len, 798 Error &error, 799 lldb::addr_t *load_addr_ptr = NULL); 800 801 size_t 802 ReadScalarIntegerFromMemory (const Address& addr, 803 bool prefer_file_cache, 804 uint32_t byte_size, 805 bool is_signed, 806 Scalar &scalar, 807 Error &error); 808 809 uint64_t 810 ReadUnsignedIntegerFromMemory (const Address& addr, 811 bool prefer_file_cache, 812 size_t integer_byte_size, 813 uint64_t fail_value, 814 Error &error); 815 816 bool 817 ReadPointerFromMemory (const Address& addr, 818 bool prefer_file_cache, 819 Error &error, 820 Address &pointer_addr); 821 822 SectionLoadList& 823 GetSectionLoadList() 824 { 825 return m_section_load_list; 826 } 827 828 const SectionLoadList& 829 GetSectionLoadList() const 830 { 831 return m_section_load_list; 832 } 833 834 835 //------------------------------------------------------------------ 836 /// Load a module in this target by at the section file addresses 837 /// with an optional constant slide applied to each section. 838 /// 839 /// This function will load all top level sections at their file 840 /// addresses and apply an optional constant slide amount to each 841 /// section. This can be used to easily load a module at the same 842 /// addresses that are contained in the object file (trust that 843 /// the addresses in an object file are the correct load addresses). 844 /// 845 /// @param[in] module 846 /// The module to load. 847 /// 848 /// @param[in] slide 849 /// A constant slide to add to each file address as each section 850 /// is being loaded. 851 /// 852 /// @return 853 /// \b true if loading the module at the specified address 854 /// causes a section to be loaded when it previously wasn't, or 855 /// if a section changes load address. Returns \b false if 856 /// the sections were all already loaded at these addresses. 857 //------------------------------------------------------------------ 858 bool 859 LoadModuleWithSlide (Module *module, lldb::addr_t slide); 860 861 static Target * 862 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 863 const SymbolContext *sc_ptr); 864 865 //------------------------------------------------------------------ 866 // lldb::ExecutionContextScope pure virtual functions 867 //------------------------------------------------------------------ 868 virtual lldb::TargetSP 869 CalculateTarget (); 870 871 virtual lldb::ProcessSP 872 CalculateProcess (); 873 874 virtual lldb::ThreadSP 875 CalculateThread (); 876 877 virtual lldb::StackFrameSP 878 CalculateStackFrame (); 879 880 virtual void 881 CalculateExecutionContext (ExecutionContext &exe_ctx); 882 883 PathMappingList & 884 GetImageSearchPathList (); 885 886 ClangASTContext * 887 GetScratchClangASTContext(bool create_on_demand=true); 888 889 ClangASTImporter * 890 GetClangASTImporter(); 891 892 const char * 893 GetExpressionPrefixContentsAsCString (); 894 895 // Since expressions results can persist beyond the lifetime of a process, 896 // and the const expression results are available after a process is gone, 897 // we provide a way for expressions to be evaluated from the Target itself. 898 // If an expression is going to be run, then it should have a frame filled 899 // in in th execution context. 900 ExecutionResults 901 EvaluateExpression (const char *expression, 902 StackFrame *frame, 903 lldb_private::ExecutionPolicy execution_policy, 904 bool coerce_to_id, 905 bool unwind_on_error, 906 bool keep_in_memory, 907 lldb::DynamicValueType use_dynamic, 908 lldb::ValueObjectSP &result_valobj_sp); 909 910 ClangPersistentVariables & 911 GetPersistentVariables() 912 { 913 return m_persistent_variables; 914 } 915 916 //------------------------------------------------------------------ 917 // Target Stop Hooks 918 //------------------------------------------------------------------ 919 class StopHook : public UserID 920 { 921 public: 922 ~StopHook (); 923 924 StopHook (const StopHook &rhs); 925 926 StringList * 927 GetCommandPointer () 928 { 929 return &m_commands; 930 } 931 932 const StringList & 933 GetCommands() 934 { 935 return m_commands; 936 } 937 938 lldb::TargetSP & 939 GetTarget() 940 { 941 return m_target_sp; 942 } 943 944 void 945 SetCommands (StringList &in_commands) 946 { 947 m_commands = in_commands; 948 } 949 950 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done. 951 void 952 SetSpecifier (SymbolContextSpecifier *specifier) 953 { 954 m_specifier_sp.reset (specifier); 955 } 956 957 SymbolContextSpecifier * 958 GetSpecifier () 959 { 960 return m_specifier_sp.get(); 961 } 962 963 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done. 964 void 965 SetThreadSpecifier (ThreadSpec *specifier); 966 967 ThreadSpec * 968 GetThreadSpecifier() 969 { 970 return m_thread_spec_ap.get(); 971 } 972 973 bool 974 IsActive() 975 { 976 return m_active; 977 } 978 979 void 980 SetIsActive (bool is_active) 981 { 982 m_active = is_active; 983 } 984 985 void 986 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 987 988 private: 989 lldb::TargetSP m_target_sp; 990 StringList m_commands; 991 lldb::SymbolContextSpecifierSP m_specifier_sp; 992 std::auto_ptr<ThreadSpec> m_thread_spec_ap; 993 bool m_active; 994 995 // Use AddStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands, 996 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.) 997 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid); 998 friend class Target; 999 }; 1000 typedef STD_SHARED_PTR(StopHook) StopHookSP; 1001 1002 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook. 1003 // Returns the id of the new hook. 1004 lldb::user_id_t 1005 AddStopHook (StopHookSP &new_hook); 1006 1007 void 1008 RunStopHooks (); 1009 1010 size_t 1011 GetStopHookSize(); 1012 1013 bool 1014 SetSuppresStopHooks (bool suppress) 1015 { 1016 bool old_value = m_suppress_stop_hooks; 1017 m_suppress_stop_hooks = suppress; 1018 return old_value; 1019 } 1020 1021 bool 1022 GetSuppressStopHooks () 1023 { 1024 return m_suppress_stop_hooks; 1025 } 1026 1027// StopHookSP & 1028// GetStopHookByIndex (size_t index); 1029// 1030 bool 1031 RemoveStopHookByID (lldb::user_id_t uid); 1032 1033 void 1034 RemoveAllStopHooks (); 1035 1036 StopHookSP 1037 GetStopHookByID (lldb::user_id_t uid); 1038 1039 bool 1040 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state); 1041 1042 void 1043 SetAllStopHooksActiveState (bool active_state); 1044 1045 size_t GetNumStopHooks () const 1046 { 1047 return m_stop_hooks.size(); 1048 } 1049 1050 StopHookSP 1051 GetStopHookAtIndex (size_t index) 1052 { 1053 if (index >= GetNumStopHooks()) 1054 return StopHookSP(); 1055 StopHookCollection::iterator pos = m_stop_hooks.begin(); 1056 1057 while (index > 0) 1058 { 1059 pos++; 1060 index--; 1061 } 1062 return (*pos).second; 1063 } 1064 1065 lldb::PlatformSP 1066 GetPlatform () 1067 { 1068 return m_platform_sp; 1069 } 1070 1071 SourceManager & 1072 GetSourceManager () 1073 { 1074 return m_source_manager; 1075 } 1076 1077 //------------------------------------------------------------------ 1078 // Target::SettingsController 1079 //------------------------------------------------------------------ 1080 class SettingsController : public UserSettingsController 1081 { 1082 public: 1083 SettingsController (); 1084 1085 virtual 1086 ~SettingsController (); 1087 1088 bool 1089 SetGlobalVariable (const ConstString &var_name, 1090 const char *index_value, 1091 const char *value, 1092 const SettingEntry &entry, 1093 const VarSetOperationType op, 1094 Error&err); 1095 1096 bool 1097 GetGlobalVariable (const ConstString &var_name, 1098 StringList &value, 1099 Error &err); 1100 1101 static SettingEntry global_settings_table[]; 1102 static SettingEntry instance_settings_table[]; 1103 1104 ArchSpec & 1105 GetArchitecture () 1106 { 1107 return m_default_architecture; 1108 } 1109 protected: 1110 1111 lldb::InstanceSettingsSP 1112 CreateInstanceSettings (const char *instance_name); 1113 1114 private: 1115 1116 // Class-wide settings. 1117 ArchSpec m_default_architecture; 1118 1119 DISALLOW_COPY_AND_ASSIGN (SettingsController); 1120 }; 1121 1122 //------------------------------------------------------------------ 1123 // Methods. 1124 //------------------------------------------------------------------ 1125 lldb::SearchFilterSP 1126 GetSearchFilterForModule (const FileSpec *containingModule); 1127 1128 lldb::SearchFilterSP 1129 GetSearchFilterForModuleList (const FileSpecList *containingModuleList); 1130 1131 lldb::SearchFilterSP 1132 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); 1133 1134protected: 1135 //------------------------------------------------------------------ 1136 // Member variables. 1137 //------------------------------------------------------------------ 1138 Debugger & m_debugger; 1139 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1140 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe 1141 ArchSpec m_arch; 1142 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). 1143 SectionLoadList m_section_load_list; 1144 BreakpointList m_breakpoint_list; 1145 BreakpointList m_internal_breakpoint_list; 1146 lldb::BreakpointSP m_last_created_breakpoint; 1147 WatchpointList m_watchpoint_list; 1148 lldb::WatchpointSP m_last_created_watchpoint; 1149 // We want to tightly control the process destruction process so 1150 // we can correctly tear down everything that we need to, so the only 1151 // class that knows about the process lifespan is this target class. 1152 lldb::ProcessSP m_process_sp; 1153 lldb::SearchFilterSP m_search_filter_sp; 1154 PathMappingList m_image_search_paths; 1155 std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap; 1156 std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap; 1157 std::auto_ptr<ClangASTImporter> m_ast_importer_ap; 1158 ClangPersistentVariables m_persistent_variables; ///< These are the persistent variables associated with this process for the expression parser. 1159 1160 SourceManager m_source_manager; 1161 1162 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1163 StopHookCollection m_stop_hooks; 1164 lldb::user_id_t m_stop_hook_next_id; 1165 bool m_suppress_stop_hooks; 1166 1167 static void 1168 ImageSearchPathsChanged (const PathMappingList &path_list, 1169 void *baton); 1170 1171private: 1172 DISALLOW_COPY_AND_ASSIGN (Target); 1173}; 1174 1175} // namespace lldb_private 1176 1177#endif // liblldb_Target_h_ 1178