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