Target.h revision 2cf5ccbbbe3343a6c973d0d65ad5de178a414e30
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 LazyBool skip_prologue = eLazyBoolCalculate, 452 bool internal = false); 453 454 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list: 455 lldb::BreakpointSP 456 CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 457 const FileSpecList *source_file_list, 458 RegularExpression &source_regex, 459 bool internal = false); 460 461 // Use this to create a breakpoint from a load address 462 lldb::BreakpointSP 463 CreateBreakpoint (lldb::addr_t load_addr, 464 bool internal = false); 465 466 // Use this to create Address breakpoints: 467 lldb::BreakpointSP 468 CreateBreakpoint (Address &addr, 469 bool internal = false); 470 471 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL 472 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 473 // setting, else we use the values passed in 474 lldb::BreakpointSP 475 CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 476 const FileSpecList *containingSourceFiles, 477 RegularExpression &func_regexp, 478 LazyBool skip_prologue = eLazyBoolCalculate, 479 bool internal = false); 480 481 // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL 482 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 483 // setting, else we use the values passed in 484 lldb::BreakpointSP 485 CreateBreakpoint (const FileSpecList *containingModules, 486 const FileSpecList *containingSourceFiles, 487 const char *func_name, 488 uint32_t func_name_type_mask, 489 LazyBool skip_prologue = eLazyBoolCalculate, 490 bool internal = false); 491 492 lldb::BreakpointSP 493 CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal = false); 494 495 // This is the same as the func_name breakpoint except that you can specify a vector of names. This is cheaper 496 // than a regular expression breakpoint in the case where you just want to set a breakpoint on a set of names 497 // you already know. 498 lldb::BreakpointSP 499 CreateBreakpoint (const FileSpecList *containingModules, 500 const FileSpecList *containingSourceFiles, 501 const char *func_names[], 502 size_t num_names, 503 uint32_t func_name_type_mask, 504 LazyBool skip_prologue = eLazyBoolCalculate, 505 bool internal = false); 506 507 lldb::BreakpointSP 508 CreateBreakpoint (const FileSpecList *containingModules, 509 const FileSpecList *containingSourceFiles, 510 const std::vector<std::string> &func_names, 511 uint32_t func_name_type_mask, 512 LazyBool skip_prologue = eLazyBoolCalculate, 513 bool internal = false); 514 515 516 // Use this to create a general breakpoint: 517 lldb::BreakpointSP 518 CreateBreakpoint (lldb::SearchFilterSP &filter_sp, 519 lldb::BreakpointResolverSP &resolver_sp, 520 bool internal = false); 521 522 // Use this to create a watchpoint: 523 lldb::WatchpointSP 524 CreateWatchpoint (lldb::addr_t addr, 525 size_t size, 526 uint32_t type); 527 528 lldb::WatchpointSP 529 GetLastCreatedWatchpoint () 530 { 531 return m_last_created_watchpoint; 532 } 533 534 WatchpointList & 535 GetWatchpointList() 536 { 537 return m_watchpoint_list; 538 } 539 540 void 541 RemoveAllBreakpoints (bool internal_also = false); 542 543 void 544 DisableAllBreakpoints (bool internal_also = false); 545 546 void 547 EnableAllBreakpoints (bool internal_also = false); 548 549 bool 550 DisableBreakpointByID (lldb::break_id_t break_id); 551 552 bool 553 EnableBreakpointByID (lldb::break_id_t break_id); 554 555 bool 556 RemoveBreakpointByID (lldb::break_id_t break_id); 557 558 // The flag 'end_to_end', default to true, signifies that the operation is 559 // performed end to end, for both the debugger and the debuggee. 560 561 bool 562 RemoveAllWatchpoints (bool end_to_end = true); 563 564 bool 565 DisableAllWatchpoints (bool end_to_end = true); 566 567 bool 568 EnableAllWatchpoints (bool end_to_end = true); 569 570 bool 571 ClearAllWatchpointHitCounts (); 572 573 bool 574 IgnoreAllWatchpoints (uint32_t ignore_count); 575 576 bool 577 DisableWatchpointByID (lldb::watch_id_t watch_id); 578 579 bool 580 EnableWatchpointByID (lldb::watch_id_t watch_id); 581 582 bool 583 RemoveWatchpointByID (lldb::watch_id_t watch_id); 584 585 bool 586 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); 587 588 void 589 ModulesDidLoad (ModuleList &module_list); 590 591 void 592 ModulesDidUnload (ModuleList &module_list); 593 594 595 //------------------------------------------------------------------ 596 /// Get \a load_addr as a callable code load address for this target 597 /// 598 /// Take \a load_addr and potentially add any address bits that are 599 /// needed to make the address callable. For ARM this can set bit 600 /// zero (if it already isn't) if \a load_addr is a thumb function. 601 /// If \a addr_class is set to eAddressClassInvalid, then the address 602 /// adjustment will always happen. If it is set to an address class 603 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 604 /// returned. 605 //------------------------------------------------------------------ 606 lldb::addr_t 607 GetCallableLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const; 608 609 //------------------------------------------------------------------ 610 /// Get \a load_addr as an opcode for this target. 611 /// 612 /// Take \a load_addr and potentially strip any address bits that are 613 /// needed to make the address point to an opcode. For ARM this can 614 /// clear bit zero (if it already isn't) if \a load_addr is a 615 /// thumb function and load_addr is in code. 616 /// If \a addr_class is set to eAddressClassInvalid, then the address 617 /// adjustment will always happen. If it is set to an address class 618 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 619 /// returned. 620 //------------------------------------------------------------------ 621 lldb::addr_t 622 GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const; 623 624protected: 625 void 626 ModuleAdded (lldb::ModuleSP &module_sp); 627 628 void 629 ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp); 630 631public: 632 //------------------------------------------------------------------ 633 /// Gets the module for the main executable. 634 /// 635 /// Each process has a notion of a main executable that is the file 636 /// that will be executed or attached to. Executable files can have 637 /// dependent modules that are discovered from the object files, or 638 /// discovered at runtime as things are dynamically loaded. 639 /// 640 /// @return 641 /// The shared pointer to the executable module which can 642 /// contains a NULL Module object if no executable has been 643 /// set. 644 /// 645 /// @see DynamicLoader 646 /// @see ObjectFile::GetDependentModules (FileSpecList&) 647 /// @see Process::SetExecutableModule(lldb::ModuleSP&) 648 //------------------------------------------------------------------ 649 lldb::ModuleSP 650 GetExecutableModule (); 651 652 Module* 653 GetExecutableModulePointer (); 654 655 //------------------------------------------------------------------ 656 /// Set the main executable module. 657 /// 658 /// Each process has a notion of a main executable that is the file 659 /// that will be executed or attached to. Executable files can have 660 /// dependent modules that are discovered from the object files, or 661 /// discovered at runtime as things are dynamically loaded. 662 /// 663 /// Setting the executable causes any of the current dependant 664 /// image information to be cleared and replaced with the static 665 /// dependent image information found by calling 666 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 667 /// executable and any modules on which it depends. Calling 668 /// Process::GetImages() will return the newly found images that 669 /// were obtained from all of the object files. 670 /// 671 /// @param[in] module_sp 672 /// A shared pointer reference to the module that will become 673 /// the main executable for this process. 674 /// 675 /// @param[in] get_dependent_files 676 /// If \b true then ask the object files to track down any 677 /// known dependent files. 678 /// 679 /// @see ObjectFile::GetDependentModules (FileSpecList&) 680 /// @see Process::GetImages() 681 //------------------------------------------------------------------ 682 void 683 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); 684 685 //------------------------------------------------------------------ 686 /// Get accessor for the images for this process. 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. After 692 /// a main executable has been set, the images will contain a list 693 /// of all the files that the executable depends upon as far as the 694 /// object files know. These images will usually contain valid file 695 /// virtual addresses only. When the process is launched or attached 696 /// to, the DynamicLoader plug-in will discover where these images 697 /// were loaded in memory and will resolve the load virtual 698 /// addresses is each image, and also in images that are loaded by 699 /// code. 700 /// 701 /// @return 702 /// A list of Module objects in a module list. 703 //------------------------------------------------------------------ 704 ModuleList& 705 GetImages () 706 { 707 return m_images; 708 } 709 710 const ModuleList& 711 GetImages () const 712 { 713 return m_images; 714 } 715 716 717 //------------------------------------------------------------------ 718 /// Return whether this FileSpec corresponds to a module that should be considered for general searches. 719 /// 720 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 721 /// and any module that returns \b true will not be searched. Note the 722 /// SearchFilterForNonModuleSpecificSearches is the search filter that 723 /// gets used in the CreateBreakpoint calls when no modules is provided. 724 /// 725 /// The target call at present just consults the Platform's call of the 726 /// same name. 727 /// 728 /// @param[in] module_sp 729 /// A shared pointer reference to the module that checked. 730 /// 731 /// @return \b true if the module should be excluded, \b false otherwise. 732 //------------------------------------------------------------------ 733 bool 734 ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec); 735 736 //------------------------------------------------------------------ 737 /// Return whether this module should be considered for general searches. 738 /// 739 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 740 /// and any module that returns \b true will not be searched. Note the 741 /// SearchFilterForNonModuleSpecificSearches is the search filter that 742 /// gets used in the CreateBreakpoint calls when no modules is provided. 743 /// 744 /// The target call at present just consults the Platform's call of the 745 /// same name. 746 /// 747 /// FIXME: When we get time we should add a way for the user to set modules that they 748 /// don't want searched, in addition to or instead of the platform ones. 749 /// 750 /// @param[in] module_sp 751 /// A shared pointer reference to the module that checked. 752 /// 753 /// @return \b true if the module should be excluded, \b false otherwise. 754 //------------------------------------------------------------------ 755 bool 756 ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp); 757 758 ArchSpec & 759 GetArchitecture () 760 { 761 return m_arch; 762 } 763 764 const ArchSpec & 765 GetArchitecture () const 766 { 767 return m_arch; 768 } 769 770 //------------------------------------------------------------------ 771 /// Set the architecture for this target. 772 /// 773 /// If the current target has no Images read in, then this just sets the architecture, which will 774 /// be used to select the architecture of the ExecutableModule when that is set. 775 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different 776 /// architecture from the currently selected one will reset the ExecutableModule to that slice 777 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not 778 /// contain a fork of this architecture, then this code will return false, and the architecture 779 /// won't be changed. 780 /// If the input arch_spec is the same as the already set architecture, this is a no-op. 781 /// 782 /// @param[in] arch_spec 783 /// The new architecture. 784 /// 785 /// @return 786 /// \b true if the architecture was successfully set, \bfalse otherwise. 787 //------------------------------------------------------------------ 788 bool 789 SetArchitecture (const ArchSpec &arch_spec); 790 791 Debugger & 792 GetDebugger () 793 { 794 return m_debugger; 795 } 796 797 size_t 798 ReadMemoryFromFileCache (const Address& addr, 799 void *dst, 800 size_t dst_len, 801 Error &error); 802 803 // Reading memory through the target allows us to skip going to the process 804 // for reading memory if possible and it allows us to try and read from 805 // any constant sections in our object files on disk. If you always want 806 // live program memory, read straight from the process. If you possibly 807 // want to read from const sections in object files, read from the target. 808 // This version of ReadMemory will try and read memory from the process 809 // if the process is alive. The order is: 810 // 1 - if (prefer_file_cache == true) then read from object file cache 811 // 2 - if there is a valid process, try and read from its memory 812 // 3 - if (prefer_file_cache == false) then read from object file cache 813 size_t 814 ReadMemory (const Address& addr, 815 bool prefer_file_cache, 816 void *dst, 817 size_t dst_len, 818 Error &error, 819 lldb::addr_t *load_addr_ptr = NULL); 820 821 size_t 822 ReadScalarIntegerFromMemory (const Address& addr, 823 bool prefer_file_cache, 824 uint32_t byte_size, 825 bool is_signed, 826 Scalar &scalar, 827 Error &error); 828 829 uint64_t 830 ReadUnsignedIntegerFromMemory (const Address& addr, 831 bool prefer_file_cache, 832 size_t integer_byte_size, 833 uint64_t fail_value, 834 Error &error); 835 836 bool 837 ReadPointerFromMemory (const Address& addr, 838 bool prefer_file_cache, 839 Error &error, 840 Address &pointer_addr); 841 842 SectionLoadList& 843 GetSectionLoadList() 844 { 845 return m_section_load_list; 846 } 847 848 const SectionLoadList& 849 GetSectionLoadList() const 850 { 851 return m_section_load_list; 852 } 853 854 static Target * 855 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 856 const SymbolContext *sc_ptr); 857 858 //------------------------------------------------------------------ 859 // lldb::ExecutionContextScope pure virtual functions 860 //------------------------------------------------------------------ 861 virtual lldb::TargetSP 862 CalculateTarget (); 863 864 virtual lldb::ProcessSP 865 CalculateProcess (); 866 867 virtual lldb::ThreadSP 868 CalculateThread (); 869 870 virtual lldb::StackFrameSP 871 CalculateStackFrame (); 872 873 virtual void 874 CalculateExecutionContext (ExecutionContext &exe_ctx); 875 876 PathMappingList & 877 GetImageSearchPathList (); 878 879 ClangASTContext * 880 GetScratchClangASTContext(bool create_on_demand=true); 881 882 ClangASTImporter * 883 GetClangASTImporter(); 884 885 const char * 886 GetExpressionPrefixContentsAsCString (); 887 888 // Since expressions results can persist beyond the lifetime of a process, 889 // and the const expression results are available after a process is gone, 890 // we provide a way for expressions to be evaluated from the Target itself. 891 // If an expression is going to be run, then it should have a frame filled 892 // in in th execution context. 893 ExecutionResults 894 EvaluateExpression (const char *expression, 895 StackFrame *frame, 896 lldb_private::ExecutionPolicy execution_policy, 897 bool coerce_to_id, 898 bool unwind_on_error, 899 bool keep_in_memory, 900 lldb::DynamicValueType use_dynamic, 901 lldb::ValueObjectSP &result_valobj_sp); 902 903 ClangPersistentVariables & 904 GetPersistentVariables() 905 { 906 return m_persistent_variables; 907 } 908 909 //------------------------------------------------------------------ 910 // Target Stop Hooks 911 //------------------------------------------------------------------ 912 class StopHook : public UserID 913 { 914 public: 915 ~StopHook (); 916 917 StopHook (const StopHook &rhs); 918 919 StringList * 920 GetCommandPointer () 921 { 922 return &m_commands; 923 } 924 925 const StringList & 926 GetCommands() 927 { 928 return m_commands; 929 } 930 931 lldb::TargetSP & 932 GetTarget() 933 { 934 return m_target_sp; 935 } 936 937 void 938 SetCommands (StringList &in_commands) 939 { 940 m_commands = in_commands; 941 } 942 943 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done. 944 void 945 SetSpecifier (SymbolContextSpecifier *specifier) 946 { 947 m_specifier_sp.reset (specifier); 948 } 949 950 SymbolContextSpecifier * 951 GetSpecifier () 952 { 953 return m_specifier_sp.get(); 954 } 955 956 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done. 957 void 958 SetThreadSpecifier (ThreadSpec *specifier); 959 960 ThreadSpec * 961 GetThreadSpecifier() 962 { 963 return m_thread_spec_ap.get(); 964 } 965 966 bool 967 IsActive() 968 { 969 return m_active; 970 } 971 972 void 973 SetIsActive (bool is_active) 974 { 975 m_active = is_active; 976 } 977 978 void 979 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 980 981 private: 982 lldb::TargetSP m_target_sp; 983 StringList m_commands; 984 lldb::SymbolContextSpecifierSP m_specifier_sp; 985 std::auto_ptr<ThreadSpec> m_thread_spec_ap; 986 bool m_active; 987 988 // Use AddStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands, 989 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.) 990 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid); 991 friend class Target; 992 }; 993 typedef STD_SHARED_PTR(StopHook) StopHookSP; 994 995 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook. 996 // Returns the id of the new hook. 997 lldb::user_id_t 998 AddStopHook (StopHookSP &new_hook); 999 1000 void 1001 RunStopHooks (); 1002 1003 size_t 1004 GetStopHookSize(); 1005 1006 bool 1007 SetSuppresStopHooks (bool suppress) 1008 { 1009 bool old_value = m_suppress_stop_hooks; 1010 m_suppress_stop_hooks = suppress; 1011 return old_value; 1012 } 1013 1014 bool 1015 GetSuppressStopHooks () 1016 { 1017 return m_suppress_stop_hooks; 1018 } 1019 1020 bool 1021 SetSuppressSyntheticValue (bool suppress) 1022 { 1023 bool old_value = m_suppress_synthetic_value; 1024 m_suppress_synthetic_value = suppress; 1025 return old_value; 1026 } 1027 1028 bool 1029 GetSuppressSyntheticValue () 1030 { 1031 return m_suppress_synthetic_value; 1032 } 1033 1034// StopHookSP & 1035// GetStopHookByIndex (size_t index); 1036// 1037 bool 1038 RemoveStopHookByID (lldb::user_id_t uid); 1039 1040 void 1041 RemoveAllStopHooks (); 1042 1043 StopHookSP 1044 GetStopHookByID (lldb::user_id_t uid); 1045 1046 bool 1047 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state); 1048 1049 void 1050 SetAllStopHooksActiveState (bool active_state); 1051 1052 size_t GetNumStopHooks () const 1053 { 1054 return m_stop_hooks.size(); 1055 } 1056 1057 StopHookSP 1058 GetStopHookAtIndex (size_t index) 1059 { 1060 if (index >= GetNumStopHooks()) 1061 return StopHookSP(); 1062 StopHookCollection::iterator pos = m_stop_hooks.begin(); 1063 1064 while (index > 0) 1065 { 1066 pos++; 1067 index--; 1068 } 1069 return (*pos).second; 1070 } 1071 1072 lldb::PlatformSP 1073 GetPlatform () 1074 { 1075 return m_platform_sp; 1076 } 1077 1078 void 1079 SetPlatform (const lldb::PlatformSP &platform_sp) 1080 { 1081 m_platform_sp = platform_sp; 1082 } 1083 1084 SourceManager & 1085 GetSourceManager () 1086 { 1087 return m_source_manager; 1088 } 1089 1090 //------------------------------------------------------------------ 1091 // Target::SettingsController 1092 //------------------------------------------------------------------ 1093 class SettingsController : public UserSettingsController 1094 { 1095 public: 1096 SettingsController (); 1097 1098 virtual 1099 ~SettingsController (); 1100 1101 bool 1102 SetGlobalVariable (const ConstString &var_name, 1103 const char *index_value, 1104 const char *value, 1105 const SettingEntry &entry, 1106 const VarSetOperationType op, 1107 Error&err); 1108 1109 bool 1110 GetGlobalVariable (const ConstString &var_name, 1111 StringList &value, 1112 Error &err); 1113 1114 static SettingEntry global_settings_table[]; 1115 static SettingEntry instance_settings_table[]; 1116 1117 ArchSpec & 1118 GetArchitecture () 1119 { 1120 return m_default_architecture; 1121 } 1122 protected: 1123 1124 lldb::InstanceSettingsSP 1125 CreateInstanceSettings (const char *instance_name); 1126 1127 private: 1128 1129 // Class-wide settings. 1130 ArchSpec m_default_architecture; 1131 1132 DISALLOW_COPY_AND_ASSIGN (SettingsController); 1133 }; 1134 1135 //------------------------------------------------------------------ 1136 // Methods. 1137 //------------------------------------------------------------------ 1138 lldb::SearchFilterSP 1139 GetSearchFilterForModule (const FileSpec *containingModule); 1140 1141 lldb::SearchFilterSP 1142 GetSearchFilterForModuleList (const FileSpecList *containingModuleList); 1143 1144 lldb::SearchFilterSP 1145 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); 1146 1147protected: 1148 //------------------------------------------------------------------ 1149 // Member variables. 1150 //------------------------------------------------------------------ 1151 Debugger & m_debugger; 1152 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1153 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe 1154 ArchSpec m_arch; 1155 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). 1156 SectionLoadList m_section_load_list; 1157 BreakpointList m_breakpoint_list; 1158 BreakpointList m_internal_breakpoint_list; 1159 lldb::BreakpointSP m_last_created_breakpoint; 1160 WatchpointList m_watchpoint_list; 1161 lldb::WatchpointSP m_last_created_watchpoint; 1162 // We want to tightly control the process destruction process so 1163 // we can correctly tear down everything that we need to, so the only 1164 // class that knows about the process lifespan is this target class. 1165 lldb::ProcessSP m_process_sp; 1166 bool m_valid; 1167 lldb::SearchFilterSP m_search_filter_sp; 1168 PathMappingList m_image_search_paths; 1169 std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap; 1170 std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap; 1171 std::auto_ptr<ClangASTImporter> m_ast_importer_ap; 1172 ClangPersistentVariables m_persistent_variables; ///< These are the persistent variables associated with this process for the expression parser. 1173 1174 SourceManager m_source_manager; 1175 1176 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1177 StopHookCollection m_stop_hooks; 1178 lldb::user_id_t m_stop_hook_next_id; 1179 bool m_suppress_stop_hooks; 1180 bool m_suppress_synthetic_value; 1181 1182 static void 1183 ImageSearchPathsChanged (const PathMappingList &path_list, 1184 void *baton); 1185 1186private: 1187 DISALLOW_COPY_AND_ASSIGN (Target); 1188}; 1189 1190} // namespace lldb_private 1191 1192#endif // liblldb_Target_h_ 1193