Target.h revision 334d33a19fd28cf41cba74cc61cf149e7101a603
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 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 std::string m_expr_prefix_contents; 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 std::tr1::enable_shared_from_this<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 void 344 Destroy(); 345 346 //------------------------------------------------------------------ 347 // This part handles the breakpoints. 348 //------------------------------------------------------------------ 349 350 BreakpointList & 351 GetBreakpointList(bool internal = false); 352 353 const BreakpointList & 354 GetBreakpointList(bool internal = false) const; 355 356 lldb::BreakpointSP 357 GetLastCreatedBreakpoint () 358 { 359 return m_last_created_breakpoint; 360 } 361 362 lldb::BreakpointSP 363 GetBreakpointByID (lldb::break_id_t break_id); 364 365 // Use this to create a file and line breakpoint to a given module or all module it is NULL 366 lldb::BreakpointSP 367 CreateBreakpoint (const FileSpecList *containingModules, 368 const FileSpec &file, 369 uint32_t line_no, 370 bool check_inlines, 371 bool internal = false); 372 373 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list: 374 lldb::BreakpointSP 375 CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 376 const FileSpecList *source_file_list, 377 RegularExpression &source_regex, 378 bool internal = false); 379 380 // Use this to create a breakpoint from a load address 381 lldb::BreakpointSP 382 CreateBreakpoint (lldb::addr_t load_addr, 383 bool internal = false); 384 385 // Use this to create Address breakpoints: 386 lldb::BreakpointSP 387 CreateBreakpoint (Address &addr, 388 bool internal = false); 389 390 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL 391 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 392 // setting, else we use the values passed in 393 lldb::BreakpointSP 394 CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 395 const FileSpecList *containingSourceFiles, 396 RegularExpression &func_regexp, 397 bool internal = false, 398 LazyBool skip_prologue = eLazyBoolCalculate); 399 400 // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL 401 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 402 // setting, else we use the values passed in 403 lldb::BreakpointSP 404 CreateBreakpoint (const FileSpecList *containingModules, 405 const FileSpecList *containingSourceFiles, 406 const char *func_name, 407 uint32_t func_name_type_mask, 408 bool internal = false, 409 LazyBool skip_prologue = eLazyBoolCalculate); 410 411 // Use this to create a general breakpoint: 412 lldb::BreakpointSP 413 CreateBreakpoint (lldb::SearchFilterSP &filter_sp, 414 lldb::BreakpointResolverSP &resolver_sp, 415 bool internal = false); 416 417 // Use this to create a watchpoint: 418 lldb::WatchpointSP 419 CreateWatchpoint (lldb::addr_t addr, 420 size_t size, 421 uint32_t type); 422 423 lldb::WatchpointSP 424 GetLastCreatedWatchpoint () 425 { 426 return m_last_created_watchpoint; 427 } 428 429 WatchpointList & 430 GetWatchpointList() 431 { 432 return m_watchpoint_list; 433 } 434 435 void 436 RemoveAllBreakpoints (bool internal_also = false); 437 438 void 439 DisableAllBreakpoints (bool internal_also = false); 440 441 void 442 EnableAllBreakpoints (bool internal_also = false); 443 444 bool 445 DisableBreakpointByID (lldb::break_id_t break_id); 446 447 bool 448 EnableBreakpointByID (lldb::break_id_t break_id); 449 450 bool 451 RemoveBreakpointByID (lldb::break_id_t break_id); 452 453 // The flag 'end_to_end', default to true, signifies that the operation is 454 // performed end to end, for both the debugger and the debuggee. 455 456 bool 457 RemoveAllWatchpoints (bool end_to_end = true); 458 459 bool 460 DisableAllWatchpoints (bool end_to_end = true); 461 462 bool 463 EnableAllWatchpoints (bool end_to_end = true); 464 465 bool 466 IgnoreAllWatchpoints (uint32_t ignore_count); 467 468 bool 469 DisableWatchpointByID (lldb::watch_id_t watch_id); 470 471 bool 472 EnableWatchpointByID (lldb::watch_id_t watch_id); 473 474 bool 475 RemoveWatchpointByID (lldb::watch_id_t watch_id); 476 477 bool 478 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); 479 480 void 481 ModulesDidLoad (ModuleList &module_list); 482 483 void 484 ModulesDidUnload (ModuleList &module_list); 485 486 487 //------------------------------------------------------------------ 488 /// Get \a load_addr as a callable code load address for this target 489 /// 490 /// Take \a load_addr and potentially add any address bits that are 491 /// needed to make the address callable. For ARM this can set bit 492 /// zero (if it already isn't) if \a load_addr is a thumb function. 493 /// If \a addr_class is set to eAddressClassInvalid, then the address 494 /// adjustment will always happen. If it is set to an address class 495 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 496 /// returned. 497 //------------------------------------------------------------------ 498 lldb::addr_t 499 GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 500 501 //------------------------------------------------------------------ 502 /// Get \a load_addr as an opcode for this target. 503 /// 504 /// Take \a load_addr and potentially strip any address bits that are 505 /// needed to make the address point to an opcode. For ARM this can 506 /// clear bit zero (if it already isn't) if \a load_addr is a 507 /// thumb function and load_addr is in code. 508 /// If \a addr_class is set to eAddressClassInvalid, then the address 509 /// adjustment will always happen. If it is set to an address class 510 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 511 /// returned. 512 //------------------------------------------------------------------ 513 lldb::addr_t 514 GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const; 515 516protected: 517 void 518 ModuleAdded (lldb::ModuleSP &module_sp); 519 520 void 521 ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp); 522 523public: 524 //------------------------------------------------------------------ 525 /// Gets the module for the main executable. 526 /// 527 /// Each process has a notion of a main executable that is the file 528 /// that will be executed or attached to. Executable files can have 529 /// dependent modules that are discovered from the object files, or 530 /// discovered at runtime as things are dynamically loaded. 531 /// 532 /// @return 533 /// The shared pointer to the executable module which can 534 /// contains a NULL Module object if no executable has been 535 /// set. 536 /// 537 /// @see DynamicLoader 538 /// @see ObjectFile::GetDependentModules (FileSpecList&) 539 /// @see Process::SetExecutableModule(lldb::ModuleSP&) 540 //------------------------------------------------------------------ 541 lldb::ModuleSP 542 GetExecutableModule (); 543 544 Module* 545 GetExecutableModulePointer (); 546 547 //------------------------------------------------------------------ 548 /// Set the main executable module. 549 /// 550 /// Each process has a notion of a main executable that is the file 551 /// that will be executed or attached to. Executable files can have 552 /// dependent modules that are discovered from the object files, or 553 /// discovered at runtime as things are dynamically loaded. 554 /// 555 /// Setting the executable causes any of the current dependant 556 /// image information to be cleared and replaced with the static 557 /// dependent image information found by calling 558 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 559 /// executable and any modules on which it depends. Calling 560 /// Process::GetImages() will return the newly found images that 561 /// were obtained from all of the object files. 562 /// 563 /// @param[in] module_sp 564 /// A shared pointer reference to the module that will become 565 /// the main executable for this process. 566 /// 567 /// @param[in] get_dependent_files 568 /// If \b true then ask the object files to track down any 569 /// known dependent files. 570 /// 571 /// @see ObjectFile::GetDependentModules (FileSpecList&) 572 /// @see Process::GetImages() 573 //------------------------------------------------------------------ 574 void 575 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); 576 577 //------------------------------------------------------------------ 578 /// Get accessor for the images for this process. 579 /// 580 /// Each process has a notion of a main executable that is the file 581 /// that will be executed or attached to. Executable files can have 582 /// dependent modules that are discovered from the object files, or 583 /// discovered at runtime as things are dynamically loaded. After 584 /// a main executable has been set, the images will contain a list 585 /// of all the files that the executable depends upon as far as the 586 /// object files know. These images will usually contain valid file 587 /// virtual addresses only. When the process is launched or attached 588 /// to, the DynamicLoader plug-in will discover where these images 589 /// were loaded in memory and will resolve the load virtual 590 /// addresses is each image, and also in images that are loaded by 591 /// code. 592 /// 593 /// @return 594 /// A list of Module objects in a module list. 595 //------------------------------------------------------------------ 596 ModuleList& 597 GetImages () 598 { 599 return m_images; 600 } 601 602 const ModuleList& 603 GetImages () const 604 { 605 return m_images; 606 } 607 608 609 //------------------------------------------------------------------ 610 /// Return whether this FileSpec corresponds to a module that should be considered for general searches. 611 /// 612 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 613 /// and any module that returns \b true will not be searched. Note the 614 /// SearchFilterForNonModuleSpecificSearches is the search filter that 615 /// gets used in the CreateBreakpoint calls when no modules is provided. 616 /// 617 /// The target call at present just consults the Platform's call of the 618 /// same name. 619 /// 620 /// @param[in] module_sp 621 /// A shared pointer reference to the module that checked. 622 /// 623 /// @return \b true if the module should be excluded, \b false otherwise. 624 //------------------------------------------------------------------ 625 bool 626 ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec); 627 628 //------------------------------------------------------------------ 629 /// Return whether this module should be considered for general searches. 630 /// 631 /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches 632 /// and any module that returns \b true will not be searched. Note the 633 /// SearchFilterForNonModuleSpecificSearches is the search filter that 634 /// gets used in the CreateBreakpoint calls when no modules is provided. 635 /// 636 /// The target call at present just consults the Platform's call of the 637 /// same name. 638 /// 639 /// FIXME: When we get time we should add a way for the user to set modules that they 640 /// don't want searched, in addition to or instead of the platform ones. 641 /// 642 /// @param[in] module_sp 643 /// A shared pointer reference to the module that checked. 644 /// 645 /// @return \b true if the module should be excluded, \b false otherwise. 646 //------------------------------------------------------------------ 647 bool 648 ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp); 649 650 ArchSpec & 651 GetArchitecture () 652 { 653 return m_arch; 654 } 655 656 const ArchSpec & 657 GetArchitecture () const 658 { 659 return m_arch; 660 } 661 662 //------------------------------------------------------------------ 663 /// Set the architecture for this target. 664 /// 665 /// If the current target has no Images read in, then this just sets the architecture, which will 666 /// be used to select the architecture of the ExecutableModule when that is set. 667 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different 668 /// architecture from the currently selected one will reset the ExecutableModule to that slice 669 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not 670 /// contain a fork of this architecture, then this code will return false, and the architecture 671 /// won't be changed. 672 /// If the input arch_spec is the same as the already set architecture, this is a no-op. 673 /// 674 /// @param[in] arch_spec 675 /// The new architecture. 676 /// 677 /// @return 678 /// \b true if the architecture was successfully set, \bfalse otherwise. 679 //------------------------------------------------------------------ 680 bool 681 SetArchitecture (const ArchSpec &arch_spec); 682 683 Debugger & 684 GetDebugger () 685 { 686 return m_debugger; 687 } 688 689 size_t 690 ReadMemoryFromFileCache (const Address& addr, 691 void *dst, 692 size_t dst_len, 693 Error &error); 694 695 // Reading memory through the target allows us to skip going to the process 696 // for reading memory if possible and it allows us to try and read from 697 // any constant sections in our object files on disk. If you always want 698 // live program memory, read straight from the process. If you possibly 699 // want to read from const sections in object files, read from the target. 700 // This version of ReadMemory will try and read memory from the process 701 // if the process is alive. The order is: 702 // 1 - if (prefer_file_cache == true) then read from object file cache 703 // 2 - if there is a valid process, try and read from its memory 704 // 3 - if (prefer_file_cache == false) then read from object file cache 705 size_t 706 ReadMemory (const Address& addr, 707 bool prefer_file_cache, 708 void *dst, 709 size_t dst_len, 710 Error &error, 711 lldb::addr_t *load_addr_ptr = NULL); 712 713 size_t 714 ReadScalarIntegerFromMemory (const Address& addr, 715 bool prefer_file_cache, 716 uint32_t byte_size, 717 bool is_signed, 718 Scalar &scalar, 719 Error &error); 720 721 uint64_t 722 ReadUnsignedIntegerFromMemory (const Address& addr, 723 bool prefer_file_cache, 724 size_t integer_byte_size, 725 uint64_t fail_value, 726 Error &error); 727 728 bool 729 ReadPointerFromMemory (const Address& addr, 730 bool prefer_file_cache, 731 Error &error, 732 Address &pointer_addr); 733 734 SectionLoadList& 735 GetSectionLoadList() 736 { 737 return m_section_load_list; 738 } 739 740 const SectionLoadList& 741 GetSectionLoadList() const 742 { 743 return m_section_load_list; 744 } 745 746 747 //------------------------------------------------------------------ 748 /// Load a module in this target by at the section file addresses 749 /// with an optional constant slide applied to each section. 750 /// 751 /// This function will load all top level sections at their file 752 /// addresses and apply an optional constant slide amount to each 753 /// section. This can be used to easily load a module at the same 754 /// addresses that are contained in the object file (trust that 755 /// the addresses in an object file are the correct load addresses). 756 /// 757 /// @param[in] module 758 /// The module to load. 759 /// 760 /// @param[in] slide 761 /// A constant slide to add to each file address as each section 762 /// is being loaded. 763 /// 764 /// @return 765 /// \b true if loading the module at the specified address 766 /// causes a section to be loaded when it previously wasn't, or 767 /// if a section changes load address. Returns \b false if 768 /// the sections were all already loaded at these addresses. 769 //------------------------------------------------------------------ 770 bool 771 LoadModuleWithSlide (Module *module, lldb::addr_t slide); 772 773 static Target * 774 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 775 const SymbolContext *sc_ptr); 776 777 //------------------------------------------------------------------ 778 // lldb::ExecutionContextScope pure virtual functions 779 //------------------------------------------------------------------ 780 virtual Target * 781 CalculateTarget (); 782 783 virtual Process * 784 CalculateProcess (); 785 786 virtual Thread * 787 CalculateThread (); 788 789 virtual StackFrame * 790 CalculateStackFrame (); 791 792 virtual void 793 CalculateExecutionContext (ExecutionContext &exe_ctx); 794 795 PathMappingList & 796 GetImageSearchPathList (); 797 798 ClangASTContext * 799 GetScratchClangASTContext(bool create_on_demand=true); 800 801 ClangASTImporter * 802 GetClangASTImporter(); 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 coerce_to_id, 817 bool unwind_on_error, 818 bool keep_in_memory, 819 lldb::DynamicValueType use_dynamic, 820 lldb::ValueObjectSP &result_valobj_sp); 821 822 ClangPersistentVariables & 823 GetPersistentVariables() 824 { 825 return m_persistent_variables; 826 } 827 828 //------------------------------------------------------------------ 829 // Target Stop Hooks 830 //------------------------------------------------------------------ 831 class StopHook : public UserID 832 { 833 public: 834 ~StopHook (); 835 836 StopHook (const StopHook &rhs); 837 838 StringList * 839 GetCommandPointer () 840 { 841 return &m_commands; 842 } 843 844 const StringList & 845 GetCommands() 846 { 847 return m_commands; 848 } 849 850 lldb::TargetSP & 851 GetTarget() 852 { 853 return m_target_sp; 854 } 855 856 void 857 SetCommands (StringList &in_commands) 858 { 859 m_commands = in_commands; 860 } 861 862 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done. 863 void 864 SetSpecifier (SymbolContextSpecifier *specifier) 865 { 866 m_specifier_sp.reset (specifier); 867 } 868 869 SymbolContextSpecifier * 870 GetSpecifier () 871 { 872 return m_specifier_sp.get(); 873 } 874 875 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done. 876 void 877 SetThreadSpecifier (ThreadSpec *specifier); 878 879 ThreadSpec * 880 GetThreadSpecifier() 881 { 882 return m_thread_spec_ap.get(); 883 } 884 885 bool 886 IsActive() 887 { 888 return m_active; 889 } 890 891 void 892 SetIsActive (bool is_active) 893 { 894 m_active = is_active; 895 } 896 897 void 898 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 899 900 private: 901 lldb::TargetSP m_target_sp; 902 StringList m_commands; 903 lldb::SymbolContextSpecifierSP m_specifier_sp; 904 std::auto_ptr<ThreadSpec> m_thread_spec_ap; 905 bool m_active; 906 907 // Use AddStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands, 908 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.) 909 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid); 910 friend class Target; 911 }; 912 typedef SHARED_PTR(StopHook) StopHookSP; 913 914 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook. 915 // Returns the id of the new hook. 916 lldb::user_id_t 917 AddStopHook (StopHookSP &new_hook); 918 919 void 920 RunStopHooks (); 921 922 size_t 923 GetStopHookSize(); 924 925 bool 926 SetSuppresStopHooks (bool suppress) 927 { 928 bool old_value = m_suppress_stop_hooks; 929 m_suppress_stop_hooks = suppress; 930 return old_value; 931 } 932 933 bool 934 GetSuppressStopHooks () 935 { 936 return m_suppress_stop_hooks; 937 } 938 939// StopHookSP & 940// GetStopHookByIndex (size_t index); 941// 942 bool 943 RemoveStopHookByID (lldb::user_id_t uid); 944 945 void 946 RemoveAllStopHooks (); 947 948 StopHookSP 949 GetStopHookByID (lldb::user_id_t uid); 950 951 bool 952 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state); 953 954 void 955 SetAllStopHooksActiveState (bool active_state); 956 957 size_t GetNumStopHooks () const 958 { 959 return m_stop_hooks.size(); 960 } 961 962 StopHookSP 963 GetStopHookAtIndex (size_t index) 964 { 965 if (index >= GetNumStopHooks()) 966 return StopHookSP(); 967 StopHookCollection::iterator pos = m_stop_hooks.begin(); 968 969 while (index > 0) 970 { 971 pos++; 972 index--; 973 } 974 return (*pos).second; 975 } 976 977 lldb::PlatformSP 978 GetPlatform () 979 { 980 return m_platform_sp; 981 } 982 983 SourceManager & 984 GetSourceManager () 985 { 986 return m_source_manager; 987 } 988 989 //------------------------------------------------------------------ 990 // Target::SettingsController 991 //------------------------------------------------------------------ 992 class SettingsController : public UserSettingsController 993 { 994 public: 995 SettingsController (); 996 997 virtual 998 ~SettingsController (); 999 1000 bool 1001 SetGlobalVariable (const ConstString &var_name, 1002 const char *index_value, 1003 const char *value, 1004 const SettingEntry &entry, 1005 const VarSetOperationType op, 1006 Error&err); 1007 1008 bool 1009 GetGlobalVariable (const ConstString &var_name, 1010 StringList &value, 1011 Error &err); 1012 1013 static SettingEntry global_settings_table[]; 1014 static SettingEntry instance_settings_table[]; 1015 1016 ArchSpec & 1017 GetArchitecture () 1018 { 1019 return m_default_architecture; 1020 } 1021 protected: 1022 1023 lldb::InstanceSettingsSP 1024 CreateInstanceSettings (const char *instance_name); 1025 1026 private: 1027 1028 // Class-wide settings. 1029 ArchSpec m_default_architecture; 1030 1031 DISALLOW_COPY_AND_ASSIGN (SettingsController); 1032 }; 1033 1034 1035protected: 1036 //------------------------------------------------------------------ 1037 // Member variables. 1038 //------------------------------------------------------------------ 1039 Debugger & m_debugger; 1040 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1041 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe 1042 ArchSpec m_arch; 1043 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). 1044 SectionLoadList m_section_load_list; 1045 BreakpointList m_breakpoint_list; 1046 BreakpointList m_internal_breakpoint_list; 1047 lldb::BreakpointSP m_last_created_breakpoint; 1048 WatchpointList m_watchpoint_list; 1049 lldb::WatchpointSP m_last_created_watchpoint; 1050 // We want to tightly control the process destruction process so 1051 // we can correctly tear down everything that we need to, so the only 1052 // class that knows about the process lifespan is this target class. 1053 lldb::ProcessSP m_process_sp; 1054 lldb::SearchFilterSP m_search_filter_sp; 1055 PathMappingList m_image_search_paths; 1056 std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap; 1057 std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap; 1058 std::auto_ptr<ClangASTImporter> m_ast_importer_ap; 1059 ClangPersistentVariables m_persistent_variables; ///< These are the persistent variables associated with this process for the expression parser. 1060 1061 SourceManager m_source_manager; 1062 1063 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1064 StopHookCollection m_stop_hooks; 1065 lldb::user_id_t m_stop_hook_next_id; 1066 bool m_suppress_stop_hooks; 1067 1068 //------------------------------------------------------------------ 1069 // Methods. 1070 //------------------------------------------------------------------ 1071 lldb::SearchFilterSP 1072 GetSearchFilterForModule (const FileSpec *containingModule); 1073 1074 lldb::SearchFilterSP 1075 GetSearchFilterForModuleList (const FileSpecList *containingModuleList); 1076 1077 lldb::SearchFilterSP 1078 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); 1079 1080 1081 static void 1082 ImageSearchPathsChanged (const PathMappingList &path_list, 1083 void *baton); 1084 1085private: 1086 DISALLOW_COPY_AND_ASSIGN (Target); 1087}; 1088 1089} // namespace lldb_private 1090 1091#endif // liblldb_Target_h_ 1092