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