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