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