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