Target.h revision 86827fbccc9a4d1f9993d74940f724d63d826e45
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 const Args & 133 GetRunArguments () const 134 { 135 return m_run_args; 136 } 137 138 void 139 SetRunArguments (const Args &args) 140 { 141 m_run_args = args; 142 } 143 144 void 145 GetHostEnvironmentIfNeeded (); 146 147 size_t 148 GetEnvironmentAsArgs (Args &env); 149 150 const char * 151 GetStandardInputPath () const 152 { 153 if (m_input_path.empty()) 154 return NULL; 155 return m_input_path.c_str(); 156 } 157 158 void 159 SetStandardInputPath (const char *path) 160 { 161 if (path && path[0]) 162 m_input_path.assign (path); 163 else 164 { 165 // Make sure we deallocate memory in string... 166 std::string tmp; 167 tmp.swap (m_input_path); 168 } 169 } 170 171 const char * 172 GetStandardOutputPath () const 173 { 174 if (m_output_path.empty()) 175 return NULL; 176 return m_output_path.c_str(); 177 } 178 179 void 180 SetStandardOutputPath (const char *path) 181 { 182 if (path && path[0]) 183 m_output_path.assign (path); 184 else 185 { 186 // Make sure we deallocate memory in string... 187 std::string tmp; 188 tmp.swap (m_output_path); 189 } 190 } 191 192 const char * 193 GetStandardErrorPath () const 194 { 195 if (m_error_path.empty()) 196 return NULL; 197 return m_error_path.c_str(); 198 } 199 200 void 201 SetStandardErrorPath (const char *path) 202 { 203 if (path && path[0]) 204 m_error_path.assign (path); 205 else 206 { 207 // Make sure we deallocate memory in string... 208 std::string tmp; 209 tmp.swap (m_error_path); 210 } 211 } 212 213 bool 214 GetDisableASLR () const 215 { 216 return m_disable_aslr; 217 } 218 219 void 220 SetDisableASLR (bool b) 221 { 222 m_disable_aslr = b; 223 } 224 225 bool 226 GetDisableSTDIO () const 227 { 228 return m_disable_stdio; 229 } 230 231 void 232 SetDisableSTDIO (bool b) 233 { 234 m_disable_stdio = b; 235 } 236 237 238protected: 239 240 void 241 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 242 bool pending); 243 244 const ConstString 245 CreateInstanceName (); 246 247 OptionValueFileSpec m_expr_prefix_file; 248 std::string m_expr_prefix_contents; 249 int m_prefer_dynamic_value; 250 OptionValueBoolean m_enable_synthetic_value; 251 OptionValueBoolean m_skip_prologue; 252 PathMappingList m_source_map; 253 FileSpecList m_exe_search_paths; 254 uint32_t m_max_children_display; 255 uint32_t m_max_strlen_length; 256 OptionValueBoolean m_breakpoints_use_platform_avoid; 257 typedef std::map<std::string, std::string> dictionary; 258 Args m_run_args; 259 dictionary m_env_vars; 260 std::string m_input_path; 261 std::string m_output_path; 262 std::string m_error_path; 263 bool m_disable_aslr; 264 bool m_disable_stdio; 265 bool m_inherit_host_env; 266 bool m_got_host_env; 267 268 269}; 270 271//---------------------------------------------------------------------- 272// Target 273//---------------------------------------------------------------------- 274class Target : 275 public STD_ENABLE_SHARED_FROM_THIS(Target), 276 public Broadcaster, 277 public ExecutionContextScope, 278 public TargetInstanceSettings 279{ 280public: 281 friend class TargetList; 282 283 //------------------------------------------------------------------ 284 /// Broadcaster event bits definitions. 285 //------------------------------------------------------------------ 286 enum 287 { 288 eBroadcastBitBreakpointChanged = (1 << 0), 289 eBroadcastBitModulesLoaded = (1 << 1), 290 eBroadcastBitModulesUnloaded = (1 << 2) 291 }; 292 293 // These two functions fill out the Broadcaster interface: 294 295 static ConstString &GetStaticBroadcasterClass (); 296 297 virtual ConstString &GetBroadcasterClass() const 298 { 299 return GetStaticBroadcasterClass(); 300 } 301 302 // This event data class is for use by the TargetList to broadcast new target notifications. 303 class TargetEventData : public EventData 304 { 305 public: 306 307 static const ConstString & 308 GetFlavorString (); 309 310 virtual const ConstString & 311 GetFlavor () const; 312 313 TargetEventData (const lldb::TargetSP &new_target_sp); 314 315 lldb::TargetSP & 316 GetTarget() 317 { 318 return m_target_sp; 319 } 320 321 virtual 322 ~TargetEventData(); 323 324 virtual void 325 Dump (Stream *s) const; 326 327 static const lldb::TargetSP 328 GetTargetFromEvent (const lldb::EventSP &event_sp); 329 330 static const TargetEventData * 331 GetEventDataFromEvent (const Event *event_sp); 332 333 private: 334 lldb::TargetSP m_target_sp; 335 336 DISALLOW_COPY_AND_ASSIGN (TargetEventData); 337 }; 338 339 static void 340 SettingsInitialize (); 341 342 static void 343 SettingsTerminate (); 344 345 static lldb::UserSettingsControllerSP & 346 GetSettingsController (); 347 348 static FileSpecList 349 GetDefaultExecutableSearchPaths (); 350 351 static ArchSpec 352 GetDefaultArchitecture (); 353 354 static void 355 SetDefaultArchitecture (const ArchSpec &arch); 356 357 void 358 UpdateInstanceName (); 359 360 lldb::ModuleSP 361 GetSharedModule (const ModuleSpec &module_spec, 362 Error *error_ptr = NULL); 363private: 364 //------------------------------------------------------------------ 365 /// Construct with optional file and arch. 366 /// 367 /// This member is private. Clients must use 368 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 369 /// so all targets can be tracked from the central target list. 370 /// 371 /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 372 //------------------------------------------------------------------ 373 Target (Debugger &debugger, 374 const ArchSpec &target_arch, 375 const lldb::PlatformSP &platform_sp); 376 377 // Helper function. 378 bool 379 ProcessIsValid (); 380 381public: 382 ~Target(); 383 384 Mutex & 385 GetAPIMutex () 386 { 387 return m_mutex; 388 } 389 390 void 391 DeleteCurrentProcess (); 392 393 //------------------------------------------------------------------ 394 /// Dump a description of this object to a Stream. 395 /// 396 /// Dump a description of the contents of this object to the 397 /// supplied stream \a s. The dumped content will be only what has 398 /// been loaded or parsed up to this point at which this function 399 /// is called, so this is a good way to see what has been parsed 400 /// in a target. 401 /// 402 /// @param[in] s 403 /// The stream to which to dump the object descripton. 404 //------------------------------------------------------------------ 405 void 406 Dump (Stream *s, lldb::DescriptionLevel description_level); 407 408 const lldb::ProcessSP & 409 CreateProcess (Listener &listener, 410 const char *plugin_name, 411 const FileSpec *crash_file); 412 413 const lldb::ProcessSP & 414 GetProcessSP () const; 415 416 bool 417 IsValid() 418 { 419 return m_valid; 420 } 421 422 void 423 Destroy(); 424 425 //------------------------------------------------------------------ 426 // This part handles the breakpoints. 427 //------------------------------------------------------------------ 428 429 BreakpointList & 430 GetBreakpointList(bool internal = false); 431 432 const BreakpointList & 433 GetBreakpointList(bool internal = false) const; 434 435 lldb::BreakpointSP 436 GetLastCreatedBreakpoint () 437 { 438 return m_last_created_breakpoint; 439 } 440 441 lldb::BreakpointSP 442 GetBreakpointByID (lldb::break_id_t break_id); 443 444 // Use this to create a file and line breakpoint to a given module or all module it is NULL 445 lldb::BreakpointSP 446 CreateBreakpoint (const FileSpecList *containingModules, 447 const FileSpec &file, 448 uint32_t line_no, 449 bool check_inlines, 450 LazyBool skip_prologue = eLazyBoolCalculate, 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 LazyBool skip_prologue = eLazyBoolCalculate, 478 bool internal = false); 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 LazyBool skip_prologue = eLazyBoolCalculate, 489 bool internal = false); 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 LazyBool skip_prologue = eLazyBoolCalculate, 504 bool internal = false); 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 LazyBool skip_prologue = eLazyBoolCalculate, 512 bool internal = false); 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 Error &error); 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