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