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