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