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