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 #include <list> 16 17 // Other libraries and framework includes 18 // Project includes 19 #include "lldb/lldb-public.h" 20 #include "lldb/Breakpoint/BreakpointList.h" 21 #include "lldb/Breakpoint/WatchpointList.h" 22 #include "lldb/Core/ArchSpec.h" 23 #include "lldb/Core/Broadcaster.h" 24 #include "lldb/Core/Disassembler.h" 25 #include "lldb/Core/ModuleList.h" 26 #include "lldb/Core/UserSettingsController.h" 27 #include "lldb/Target/ExecutionContextScope.h" 28 #include "lldb/Target/PathMappingList.h" 29 #include "lldb/Target/ProcessLaunchInfo.h" 30 #include "lldb/Target/SectionLoadHistory.h" 31 32 namespace lldb_private { 33 34 extern OptionEnumValueElement g_dynamic_value_types[]; 35 36 typedef enum InlineStrategy 37 { 38 eInlineBreakpointsNever = 0, 39 eInlineBreakpointsHeaders, 40 eInlineBreakpointsAlways 41 } InlineStrategy; 42 43 typedef enum LoadScriptFromSymFile 44 { 45 eLoadScriptFromSymFileTrue, 46 eLoadScriptFromSymFileFalse, 47 eLoadScriptFromSymFileWarn 48 } LoadScriptFromSymFile; 49 50 //---------------------------------------------------------------------- 51 // TargetProperties 52 //---------------------------------------------------------------------- 53 class TargetProperties : public Properties 54 { 55 public: 56 TargetProperties(Target *target); 57 58 virtual 59 ~TargetProperties(); 60 61 ArchSpec 62 GetDefaultArchitecture () const; 63 64 void 65 SetDefaultArchitecture (const ArchSpec& arch); 66 67 bool 68 GetMoveToNearestCode () const; 69 70 lldb::DynamicValueType 71 GetPreferDynamicValue() const; 72 73 bool 74 SetPreferDynamicValue (lldb::DynamicValueType d); 75 76 bool 77 GetDisableASLR () const; 78 79 void 80 SetDisableASLR (bool b); 81 82 bool 83 GetDetachOnError () const; 84 85 void 86 SetDetachOnError (bool b); 87 88 bool 89 GetDisableSTDIO () const; 90 91 void 92 SetDisableSTDIO (bool b); 93 94 const char * 95 GetDisassemblyFlavor() const; 96 97 // void 98 // SetDisassemblyFlavor(const char *flavor); 99 100 InlineStrategy 101 GetInlineStrategy () const; 102 103 const char * 104 GetArg0 () const; 105 106 void 107 SetArg0 (const char *arg); 108 109 bool 110 GetRunArguments (Args &args) const; 111 112 void 113 SetRunArguments (const Args &args); 114 115 size_t 116 GetEnvironmentAsArgs (Args &env) const; 117 118 void 119 SetEnvironmentFromArgs (const Args &env); 120 121 bool 122 GetSkipPrologue() const; 123 124 PathMappingList & 125 GetSourcePathMap () const; 126 127 FileSpecList & 128 GetExecutableSearchPaths (); 129 130 FileSpecList & 131 GetDebugFileSearchPaths (); 132 133 FileSpecList & 134 GetClangModuleSearchPaths (); 135 136 bool 137 GetEnableAutoImportClangModules () const; 138 139 bool 140 GetEnableSyntheticValue () const; 141 142 uint32_t 143 GetMaximumNumberOfChildrenToDisplay() const; 144 145 uint32_t 146 GetMaximumSizeOfStringSummary() const; 147 148 uint32_t 149 GetMaximumMemReadSize () const; 150 151 FileSpec 152 GetStandardInputPath () const; 153 154 void 155 SetStandardInputPath (const char *path); 156 157 FileSpec 158 GetStandardOutputPath () const; 159 160 void 161 SetStandardOutputPath (const char *path); 162 163 FileSpec 164 GetStandardErrorPath () const; 165 166 void 167 SetStandardErrorPath (const char *path); 168 169 bool 170 GetBreakpointsConsultPlatformAvoidList (); 171 172 const char * 173 GetExpressionPrefixContentsAsCString (); 174 175 bool 176 GetUseHexImmediates() const; 177 178 bool 179 GetUseFastStepping() const; 180 181 bool 182 GetDisplayExpressionsInCrashlogs () const; 183 184 LoadScriptFromSymFile 185 GetLoadScriptFromSymbolFile() const; 186 187 Disassembler::HexImmediateStyle 188 GetHexImmediateStyle() const; 189 190 MemoryModuleLoadLevel 191 GetMemoryModuleLoadLevel() const; 192 193 bool 194 GetUserSpecifiedTrapHandlerNames (Args &args) const; 195 196 void 197 SetUserSpecifiedTrapHandlerNames (const Args &args); 198 199 bool 200 GetNonStopModeEnabled () const; 201 202 void 203 SetNonStopModeEnabled (bool b); 204 205 bool 206 GetDisplayRuntimeSupportValues () const; 207 208 void 209 SetDisplayRuntimeSupportValues (bool b); 210 211 const ProcessLaunchInfo & 212 GetProcessLaunchInfo(); 213 214 void 215 SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info); 216 217 private: 218 //------------------------------------------------------------------ 219 // Callbacks for m_launch_info. 220 //------------------------------------------------------------------ 221 static void Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *); 222 static void RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *); 223 static void EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *); 224 static void InheritEnvValueChangedCallback(void *target_property_ptr, OptionValue *); 225 static void InputPathValueChangedCallback(void *target_property_ptr, OptionValue *); 226 static void OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *); 227 static void ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *); 228 static void DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *); 229 static void DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *); 230 static void DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *); 231 232 private: 233 //------------------------------------------------------------------ 234 // Member variables. 235 //------------------------------------------------------------------ 236 ProcessLaunchInfo m_launch_info; 237 }; 238 239 class EvaluateExpressionOptions 240 { 241 public: 242 static const uint32_t default_timeout = 500000; EvaluateExpressionOptions()243 EvaluateExpressionOptions() : 244 m_execution_policy(eExecutionPolicyOnlyWhenNeeded), 245 m_language (lldb::eLanguageTypeUnknown), 246 m_prefix (), // A prefix specific to this expression that is added after the prefix from the settings (if any) 247 m_coerce_to_id (false), 248 m_unwind_on_error (true), 249 m_ignore_breakpoints (false), 250 m_keep_in_memory (false), 251 m_try_others (true), 252 m_stop_others (true), 253 m_debug (false), 254 m_trap_exceptions (true), 255 m_generate_debug_info (false), 256 m_result_is_internal (false), 257 m_use_dynamic (lldb::eNoDynamicValues), 258 m_timeout_usec (default_timeout), 259 m_one_thread_timeout_usec (0), 260 m_cancel_callback (nullptr), 261 m_cancel_callback_baton (nullptr) 262 { 263 } 264 265 ExecutionPolicy GetExecutionPolicy()266 GetExecutionPolicy () const 267 { 268 return m_execution_policy; 269 } 270 271 void 272 SetExecutionPolicy (ExecutionPolicy policy = eExecutionPolicyAlways) 273 { 274 m_execution_policy = policy; 275 } 276 277 lldb::LanguageType GetLanguage()278 GetLanguage() const 279 { 280 return m_language; 281 } 282 283 void SetLanguage(lldb::LanguageType language)284 SetLanguage(lldb::LanguageType language) 285 { 286 m_language = language; 287 } 288 289 bool DoesCoerceToId()290 DoesCoerceToId () const 291 { 292 return m_coerce_to_id; 293 } 294 295 const char * GetPrefix()296 GetPrefix () const 297 { 298 if (m_prefix.empty()) 299 return NULL; 300 return m_prefix.c_str(); 301 } 302 303 void SetPrefix(const char * prefix)304 SetPrefix (const char *prefix) 305 { 306 if (prefix && prefix[0]) 307 m_prefix = prefix; 308 else 309 m_prefix.clear(); 310 } 311 312 void 313 SetCoerceToId (bool coerce = true) 314 { 315 m_coerce_to_id = coerce; 316 } 317 318 bool DoesUnwindOnError()319 DoesUnwindOnError () const 320 { 321 return m_unwind_on_error; 322 } 323 324 void 325 SetUnwindOnError (bool unwind = false) 326 { 327 m_unwind_on_error = unwind; 328 } 329 330 bool DoesIgnoreBreakpoints()331 DoesIgnoreBreakpoints () const 332 { 333 return m_ignore_breakpoints; 334 } 335 336 void 337 SetIgnoreBreakpoints (bool ignore = false) 338 { 339 m_ignore_breakpoints = ignore; 340 } 341 342 bool DoesKeepInMemory()343 DoesKeepInMemory () const 344 { 345 return m_keep_in_memory; 346 } 347 348 void 349 SetKeepInMemory (bool keep = true) 350 { 351 m_keep_in_memory = keep; 352 } 353 354 lldb::DynamicValueType GetUseDynamic()355 GetUseDynamic () const 356 { 357 return m_use_dynamic; 358 } 359 360 void 361 SetUseDynamic (lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget) 362 { 363 m_use_dynamic = dynamic; 364 } 365 366 uint32_t GetTimeoutUsec()367 GetTimeoutUsec () const 368 { 369 return m_timeout_usec; 370 } 371 372 void 373 SetTimeoutUsec (uint32_t timeout = 0) 374 { 375 m_timeout_usec = timeout; 376 } 377 378 uint32_t GetOneThreadTimeoutUsec()379 GetOneThreadTimeoutUsec () const 380 { 381 return m_one_thread_timeout_usec; 382 } 383 384 void 385 SetOneThreadTimeoutUsec (uint32_t timeout = 0) 386 { 387 m_one_thread_timeout_usec = timeout; 388 } 389 390 bool GetTryAllThreads()391 GetTryAllThreads () const 392 { 393 return m_try_others; 394 } 395 396 void 397 SetTryAllThreads (bool try_others = true) 398 { 399 m_try_others = try_others; 400 } 401 402 bool GetStopOthers()403 GetStopOthers () const 404 { 405 return m_stop_others; 406 } 407 408 void 409 SetStopOthers (bool stop_others = true) 410 { 411 m_stop_others = stop_others; 412 } 413 414 bool GetDebug()415 GetDebug() const 416 { 417 return m_debug; 418 } 419 420 void SetDebug(bool b)421 SetDebug(bool b) 422 { 423 m_debug = b; 424 if (m_debug) 425 m_generate_debug_info = true; 426 } 427 428 bool GetGenerateDebugInfo()429 GetGenerateDebugInfo() const 430 { 431 return m_generate_debug_info; 432 } 433 434 void SetGenerateDebugInfo(bool b)435 SetGenerateDebugInfo(bool b) 436 { 437 m_generate_debug_info = b; 438 } 439 440 bool GetTrapExceptions()441 GetTrapExceptions() const 442 { 443 return m_trap_exceptions; 444 } 445 446 void SetTrapExceptions(bool b)447 SetTrapExceptions (bool b) 448 { 449 m_trap_exceptions = b; 450 } 451 452 void SetCancelCallback(lldb::ExpressionCancelCallback callback,void * baton)453 SetCancelCallback (lldb::ExpressionCancelCallback callback, void *baton) 454 { 455 m_cancel_callback_baton = baton; 456 m_cancel_callback = callback; 457 } 458 459 bool InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase)460 InvokeCancelCallback (lldb::ExpressionEvaluationPhase phase) const 461 { 462 if (m_cancel_callback == nullptr) 463 return false; 464 else 465 return m_cancel_callback (phase, m_cancel_callback_baton); 466 } 467 468 void SetResultIsInternal(bool b)469 SetResultIsInternal (bool b) 470 { 471 m_result_is_internal = b; 472 } 473 474 bool GetResultIsInternal()475 GetResultIsInternal () const 476 { 477 return m_result_is_internal; 478 } 479 480 private: 481 ExecutionPolicy m_execution_policy; 482 lldb::LanguageType m_language; 483 std::string m_prefix; 484 bool m_coerce_to_id; 485 bool m_unwind_on_error; 486 bool m_ignore_breakpoints; 487 bool m_keep_in_memory; 488 bool m_try_others; 489 bool m_stop_others; 490 bool m_debug; 491 bool m_trap_exceptions; 492 bool m_generate_debug_info; 493 bool m_result_is_internal; 494 lldb::DynamicValueType m_use_dynamic; 495 uint32_t m_timeout_usec; 496 uint32_t m_one_thread_timeout_usec; 497 lldb::ExpressionCancelCallback m_cancel_callback; 498 void *m_cancel_callback_baton; 499 }; 500 501 //---------------------------------------------------------------------- 502 // Target 503 //---------------------------------------------------------------------- 504 class Target : 505 public std::enable_shared_from_this<Target>, 506 public TargetProperties, 507 public Broadcaster, 508 public ExecutionContextScope, 509 public ModuleList::Notifier 510 { 511 public: 512 friend class TargetList; 513 514 //------------------------------------------------------------------ 515 /// Broadcaster event bits definitions. 516 //------------------------------------------------------------------ 517 enum 518 { 519 eBroadcastBitBreakpointChanged = (1 << 0), 520 eBroadcastBitModulesLoaded = (1 << 1), 521 eBroadcastBitModulesUnloaded = (1 << 2), 522 eBroadcastBitWatchpointChanged = (1 << 3), 523 eBroadcastBitSymbolsLoaded = (1 << 4) 524 }; 525 526 // These two functions fill out the Broadcaster interface: 527 528 static ConstString &GetStaticBroadcasterClass (); 529 GetBroadcasterClass()530 virtual ConstString &GetBroadcasterClass() const 531 { 532 return GetStaticBroadcasterClass(); 533 } 534 535 // This event data class is for use by the TargetList to broadcast new target notifications. 536 class TargetEventData : public EventData 537 { 538 public: 539 TargetEventData (const lldb::TargetSP &target_sp); 540 541 TargetEventData (const lldb::TargetSP &target_sp, const ModuleList &module_list); 542 543 virtual 544 ~TargetEventData(); 545 546 static const ConstString & 547 GetFlavorString (); 548 549 virtual const ConstString & GetFlavor()550 GetFlavor () const 551 { 552 return TargetEventData::GetFlavorString (); 553 } 554 555 virtual void 556 Dump (Stream *s) const; 557 558 static const TargetEventData * 559 GetEventDataFromEvent (const Event *event_ptr); 560 561 static lldb::TargetSP 562 GetTargetFromEvent (const Event *event_ptr); 563 564 static ModuleList 565 GetModuleListFromEvent (const Event *event_ptr); 566 567 const lldb::TargetSP & GetTarget()568 GetTarget() const 569 { 570 return m_target_sp; 571 } 572 573 const ModuleList & GetModuleList()574 GetModuleList() const 575 { 576 return m_module_list; 577 } 578 579 private: 580 lldb::TargetSP m_target_sp; 581 ModuleList m_module_list; 582 583 DISALLOW_COPY_AND_ASSIGN (TargetEventData); 584 }; 585 586 static void 587 SettingsInitialize (); 588 589 static void 590 SettingsTerminate (); 591 592 static FileSpecList 593 GetDefaultExecutableSearchPaths (); 594 595 static FileSpecList 596 GetDefaultDebugFileSearchPaths (); 597 598 static FileSpecList 599 GetDefaultClangModuleSearchPaths (); 600 601 static ArchSpec 602 GetDefaultArchitecture (); 603 604 static void 605 SetDefaultArchitecture (const ArchSpec &arch); 606 607 // void 608 // UpdateInstanceName (); 609 610 lldb::ModuleSP 611 GetSharedModule (const ModuleSpec &module_spec, 612 Error *error_ptr = NULL); 613 614 //---------------------------------------------------------------------- 615 // Settings accessors 616 //---------------------------------------------------------------------- 617 618 static const lldb::TargetPropertiesSP & 619 GetGlobalProperties(); 620 621 622 private: 623 //------------------------------------------------------------------ 624 /// Construct with optional file and arch. 625 /// 626 /// This member is private. Clients must use 627 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 628 /// so all targets can be tracked from the central target list. 629 /// 630 /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 631 //------------------------------------------------------------------ 632 Target (Debugger &debugger, 633 const ArchSpec &target_arch, 634 const lldb::PlatformSP &platform_sp, 635 bool is_dummy_target); 636 637 // Helper function. 638 bool 639 ProcessIsValid (); 640 641 // Copy breakpoints, stop hooks and so forth from the dummy target: 642 void 643 PrimeFromDummyTarget(Target *dummy_target); 644 645 void 646 AddBreakpoint(lldb::BreakpointSP breakpoint_sp, bool internal); 647 648 public: 649 ~Target(); 650 651 Mutex & GetAPIMutex()652 GetAPIMutex () 653 { 654 return m_mutex; 655 } 656 657 void 658 DeleteCurrentProcess (); 659 660 void 661 CleanupProcess (); 662 //------------------------------------------------------------------ 663 /// Dump a description of this object to a Stream. 664 /// 665 /// Dump a description of the contents of this object to the 666 /// supplied stream \a s. The dumped content will be only what has 667 /// been loaded or parsed up to this point at which this function 668 /// is called, so this is a good way to see what has been parsed 669 /// in a target. 670 /// 671 /// @param[in] s 672 /// The stream to which to dump the object description. 673 //------------------------------------------------------------------ 674 void 675 Dump (Stream *s, lldb::DescriptionLevel description_level); 676 677 const lldb::ProcessSP & 678 CreateProcess (Listener &listener, 679 const char *plugin_name, 680 const FileSpec *crash_file); 681 682 const lldb::ProcessSP & 683 GetProcessSP () const; 684 685 bool IsValid()686 IsValid() 687 { 688 return m_valid; 689 } 690 691 void 692 Destroy(); 693 694 Error 695 Launch (ProcessLaunchInfo &launch_info, 696 Stream *stream); // Optional stream to receive first stop info 697 698 Error 699 Attach (ProcessAttachInfo &attach_info, 700 Stream *stream); // Optional stream to receive first stop info 701 702 //------------------------------------------------------------------ 703 // This part handles the breakpoints. 704 //------------------------------------------------------------------ 705 706 BreakpointList & 707 GetBreakpointList(bool internal = false); 708 709 const BreakpointList & 710 GetBreakpointList(bool internal = false) const; 711 712 lldb::BreakpointSP GetLastCreatedBreakpoint()713 GetLastCreatedBreakpoint () 714 { 715 return m_last_created_breakpoint; 716 } 717 718 lldb::BreakpointSP 719 GetBreakpointByID (lldb::break_id_t break_id); 720 721 // Use this to create a file and line breakpoint to a given module or all module it is NULL 722 lldb::BreakpointSP 723 CreateBreakpoint (const FileSpecList *containingModules, 724 const FileSpec &file, 725 uint32_t line_no, 726 LazyBool check_inlines, 727 LazyBool skip_prologue, 728 bool internal, 729 bool request_hardware, 730 LazyBool move_to_nearest_code); 731 732 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list: 733 lldb::BreakpointSP 734 CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 735 const FileSpecList *source_file_list, 736 RegularExpression &source_regex, 737 bool internal, 738 bool request_hardware, 739 LazyBool move_to_nearest_code); 740 741 // Use this to create a breakpoint from a load address 742 lldb::BreakpointSP 743 CreateBreakpoint (lldb::addr_t load_addr, 744 bool internal, 745 bool request_hardware); 746 747 // Use this to create Address breakpoints: 748 lldb::BreakpointSP 749 CreateBreakpoint (Address &addr, 750 bool internal, 751 bool request_hardware); 752 753 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL 754 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 755 // setting, else we use the values passed in 756 lldb::BreakpointSP 757 CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 758 const FileSpecList *containingSourceFiles, 759 RegularExpression &func_regexp, 760 LazyBool skip_prologue, 761 bool internal, 762 bool request_hardware); 763 764 // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL 765 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target 766 // setting, else we use the values passed in. 767 // func_name_type_mask is or'ed values from the FunctionNameType enum. 768 lldb::BreakpointSP 769 CreateBreakpoint (const FileSpecList *containingModules, 770 const FileSpecList *containingSourceFiles, 771 const char *func_name, 772 uint32_t func_name_type_mask, 773 LazyBool skip_prologue, 774 bool internal, 775 bool request_hardware); 776 777 lldb::BreakpointSP 778 CreateExceptionBreakpoint (enum lldb::LanguageType language, 779 bool catch_bp, 780 bool throw_bp, 781 bool internal, 782 Args *additional_args = nullptr, 783 Error *additional_args_error = nullptr); 784 785 // This is the same as the func_name breakpoint except that you can specify a vector of names. This is cheaper 786 // than a regular expression breakpoint in the case where you just want to set a breakpoint on a set of names 787 // you already know. 788 // func_name_type_mask is or'ed values from the FunctionNameType enum. 789 lldb::BreakpointSP 790 CreateBreakpoint (const FileSpecList *containingModules, 791 const FileSpecList *containingSourceFiles, 792 const char *func_names[], 793 size_t num_names, 794 uint32_t func_name_type_mask, 795 LazyBool skip_prologue, 796 bool internal, 797 bool request_hardware); 798 799 lldb::BreakpointSP 800 CreateBreakpoint (const FileSpecList *containingModules, 801 const FileSpecList *containingSourceFiles, 802 const std::vector<std::string> &func_names, 803 uint32_t func_name_type_mask, 804 LazyBool skip_prologue, 805 bool internal, 806 bool request_hardware); 807 808 809 // Use this to create a general breakpoint: 810 lldb::BreakpointSP 811 CreateBreakpoint (lldb::SearchFilterSP &filter_sp, 812 lldb::BreakpointResolverSP &resolver_sp, 813 bool internal, 814 bool request_hardware, 815 bool resolve_indirect_symbols); 816 817 // Use this to create a watchpoint: 818 lldb::WatchpointSP 819 CreateWatchpoint (lldb::addr_t addr, 820 size_t size, 821 const ClangASTType *type, 822 uint32_t kind, 823 Error &error); 824 825 lldb::WatchpointSP GetLastCreatedWatchpoint()826 GetLastCreatedWatchpoint () 827 { 828 return m_last_created_watchpoint; 829 } 830 831 WatchpointList & GetWatchpointList()832 GetWatchpointList() 833 { 834 return m_watchpoint_list; 835 } 836 837 void 838 RemoveAllBreakpoints (bool internal_also = false); 839 840 void 841 DisableAllBreakpoints (bool internal_also = false); 842 843 void 844 EnableAllBreakpoints (bool internal_also = false); 845 846 bool 847 DisableBreakpointByID (lldb::break_id_t break_id); 848 849 bool 850 EnableBreakpointByID (lldb::break_id_t break_id); 851 852 bool 853 RemoveBreakpointByID (lldb::break_id_t break_id); 854 855 // The flag 'end_to_end', default to true, signifies that the operation is 856 // performed end to end, for both the debugger and the debuggee. 857 858 bool 859 RemoveAllWatchpoints (bool end_to_end = true); 860 861 bool 862 DisableAllWatchpoints (bool end_to_end = true); 863 864 bool 865 EnableAllWatchpoints (bool end_to_end = true); 866 867 bool 868 ClearAllWatchpointHitCounts (); 869 870 bool 871 ClearAllWatchpointHistoricValues (); 872 873 bool 874 IgnoreAllWatchpoints (uint32_t ignore_count); 875 876 bool 877 DisableWatchpointByID (lldb::watch_id_t watch_id); 878 879 bool 880 EnableWatchpointByID (lldb::watch_id_t watch_id); 881 882 bool 883 RemoveWatchpointByID (lldb::watch_id_t watch_id); 884 885 bool 886 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); 887 888 //------------------------------------------------------------------ 889 /// Get \a load_addr as a callable code load address for this target 890 /// 891 /// Take \a load_addr and potentially add any address bits that are 892 /// needed to make the address callable. For ARM this can set bit 893 /// zero (if it already isn't) if \a load_addr is a thumb function. 894 /// If \a addr_class is set to eAddressClassInvalid, then the address 895 /// adjustment will always happen. If it is set to an address class 896 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 897 /// returned. 898 //------------------------------------------------------------------ 899 lldb::addr_t 900 GetCallableLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const; 901 902 //------------------------------------------------------------------ 903 /// Get \a load_addr as an opcode for this target. 904 /// 905 /// Take \a load_addr and potentially strip any address bits that are 906 /// needed to make the address point to an opcode. For ARM this can 907 /// clear bit zero (if it already isn't) if \a load_addr is a 908 /// thumb function and load_addr is in code. 909 /// If \a addr_class is set to eAddressClassInvalid, then the address 910 /// adjustment will always happen. If it is set to an address class 911 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 912 /// returned. 913 //------------------------------------------------------------------ 914 lldb::addr_t 915 GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const; 916 917 protected: 918 //------------------------------------------------------------------ 919 /// Implementing of ModuleList::Notifier. 920 //------------------------------------------------------------------ 921 922 virtual void 923 ModuleAdded (const ModuleList& module_list, const lldb::ModuleSP& module_sp); 924 925 virtual void 926 ModuleRemoved (const ModuleList& module_list, const lldb::ModuleSP& module_sp); 927 928 virtual void 929 ModuleUpdated (const ModuleList& module_list, 930 const lldb::ModuleSP& old_module_sp, 931 const lldb::ModuleSP& new_module_sp); 932 virtual void 933 WillClearList (const ModuleList& module_list); 934 935 public: 936 937 void 938 ModulesDidLoad (ModuleList &module_list); 939 940 void 941 ModulesDidUnload (ModuleList &module_list, bool delete_locations); 942 943 void 944 SymbolsDidLoad (ModuleList &module_list); 945 946 void 947 ClearModules(bool delete_locations); 948 949 //------------------------------------------------------------------ 950 /// Called as the last function in Process::DidExec(). 951 /// 952 /// Process::DidExec() will clear a lot of state in the process, 953 /// then try to reload a dynamic loader plugin to discover what 954 /// binaries are currently available and then this function should 955 /// be called to allow the target to do any cleanup after everything 956 /// has been figured out. It can remove breakpoints that no longer 957 /// make sense as the exec might have changed the target 958 /// architecture, and unloaded some modules that might get deleted. 959 //------------------------------------------------------------------ 960 void 961 DidExec (); 962 963 //------------------------------------------------------------------ 964 /// Gets the module for the main executable. 965 /// 966 /// Each process has a notion of a main executable that is the file 967 /// that will be executed or attached to. Executable files can have 968 /// dependent modules that are discovered from the object files, or 969 /// discovered at runtime as things are dynamically loaded. 970 /// 971 /// @return 972 /// The shared pointer to the executable module which can 973 /// contains a NULL Module object if no executable has been 974 /// set. 975 /// 976 /// @see DynamicLoader 977 /// @see ObjectFile::GetDependentModules (FileSpecList&) 978 /// @see Process::SetExecutableModule(lldb::ModuleSP&) 979 //------------------------------------------------------------------ 980 lldb::ModuleSP 981 GetExecutableModule (); 982 983 Module* 984 GetExecutableModulePointer (); 985 986 //------------------------------------------------------------------ 987 /// Set the main executable module. 988 /// 989 /// Each process has a notion of a main executable that is the file 990 /// that will be executed or attached to. Executable files can have 991 /// dependent modules that are discovered from the object files, or 992 /// discovered at runtime as things are dynamically loaded. 993 /// 994 /// Setting the executable causes any of the current dependant 995 /// image information to be cleared and replaced with the static 996 /// dependent image information found by calling 997 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 998 /// executable and any modules on which it depends. Calling 999 /// Process::GetImages() will return the newly found images that 1000 /// were obtained from all of the object files. 1001 /// 1002 /// @param[in] module_sp 1003 /// A shared pointer reference to the module that will become 1004 /// the main executable for this process. 1005 /// 1006 /// @param[in] get_dependent_files 1007 /// If \b true then ask the object files to track down any 1008 /// known dependent files. 1009 /// 1010 /// @see ObjectFile::GetDependentModules (FileSpecList&) 1011 /// @see Process::GetImages() 1012 //------------------------------------------------------------------ 1013 void 1014 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); 1015 1016 bool 1017 LoadScriptingResources (std::list<Error>& errors, 1018 Stream* feedback_stream = NULL, 1019 bool continue_on_error = true) 1020 { 1021 return m_images.LoadScriptingResourcesInTarget(this,errors,feedback_stream,continue_on_error); 1022 } 1023 1024 //------------------------------------------------------------------ 1025 /// Get accessor for the images for this process. 1026 /// 1027 /// Each process has a notion of a main executable that is the file 1028 /// that will be executed or attached to. Executable files can have 1029 /// dependent modules that are discovered from the object files, or 1030 /// discovered at runtime as things are dynamically loaded. After 1031 /// a main executable has been set, the images will contain a list 1032 /// of all the files that the executable depends upon as far as the 1033 /// object files know. These images will usually contain valid file 1034 /// virtual addresses only. When the process is launched or attached 1035 /// to, the DynamicLoader plug-in will discover where these images 1036 /// were loaded in memory and will resolve the load virtual 1037 /// addresses is each image, and also in images that are loaded by 1038 /// code. 1039 /// 1040 /// @return 1041 /// A list of Module objects in a module list. 1042 //------------------------------------------------------------------ 1043 const ModuleList& GetImages()1044 GetImages () const 1045 { 1046 return m_images; 1047 } 1048 1049 ModuleList& GetImages()1050 GetImages () 1051 { 1052 return m_images; 1053 } 1054 1055 //------------------------------------------------------------------ 1056 /// Return whether this FileSpec corresponds to a module that should be considered for general searches. 1057 /// 1058 /// This API will be consulted by the SearchFilterForUnconstrainedSearches 1059 /// and any module that returns \b true will not be searched. Note the 1060 /// SearchFilterForUnconstrainedSearches is the search filter that 1061 /// gets used in the CreateBreakpoint calls when no modules is provided. 1062 /// 1063 /// The target call at present just consults the Platform's call of the 1064 /// same name. 1065 /// 1066 /// @param[in] module_sp 1067 /// A shared pointer reference to the module that checked. 1068 /// 1069 /// @return \b true if the module should be excluded, \b false otherwise. 1070 //------------------------------------------------------------------ 1071 bool 1072 ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_spec); 1073 1074 //------------------------------------------------------------------ 1075 /// Return whether this module should be considered for general searches. 1076 /// 1077 /// This API will be consulted by the SearchFilterForUnconstrainedSearches 1078 /// and any module that returns \b true will not be searched. Note the 1079 /// SearchFilterForUnconstrainedSearches is the search filter that 1080 /// gets used in the CreateBreakpoint calls when no modules is provided. 1081 /// 1082 /// The target call at present just consults the Platform's call of the 1083 /// same name. 1084 /// 1085 /// FIXME: When we get time we should add a way for the user to set modules that they 1086 /// don't want searched, in addition to or instead of the platform ones. 1087 /// 1088 /// @param[in] module_sp 1089 /// A shared pointer reference to the module that checked. 1090 /// 1091 /// @return \b true if the module should be excluded, \b false otherwise. 1092 //------------------------------------------------------------------ 1093 bool 1094 ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp); 1095 1096 const ArchSpec & GetArchitecture()1097 GetArchitecture () const 1098 { 1099 return m_arch; 1100 } 1101 1102 //------------------------------------------------------------------ 1103 /// Set the architecture for this target. 1104 /// 1105 /// If the current target has no Images read in, then this just sets the architecture, which will 1106 /// be used to select the architecture of the ExecutableModule when that is set. 1107 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different 1108 /// architecture from the currently selected one will reset the ExecutableModule to that slice 1109 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not 1110 /// contain a fork of this architecture, then this code will return false, and the architecture 1111 /// won't be changed. 1112 /// If the input arch_spec is the same as the already set architecture, this is a no-op. 1113 /// 1114 /// @param[in] arch_spec 1115 /// The new architecture. 1116 /// 1117 /// @return 1118 /// \b true if the architecture was successfully set, \bfalse otherwise. 1119 //------------------------------------------------------------------ 1120 bool 1121 SetArchitecture (const ArchSpec &arch_spec); 1122 1123 bool 1124 MergeArchitecture (const ArchSpec &arch_spec); 1125 1126 Debugger & GetDebugger()1127 GetDebugger () 1128 { 1129 return m_debugger; 1130 } 1131 1132 size_t 1133 ReadMemoryFromFileCache (const Address& addr, 1134 void *dst, 1135 size_t dst_len, 1136 Error &error); 1137 1138 // Reading memory through the target allows us to skip going to the process 1139 // for reading memory if possible and it allows us to try and read from 1140 // any constant sections in our object files on disk. If you always want 1141 // live program memory, read straight from the process. If you possibly 1142 // want to read from const sections in object files, read from the target. 1143 // This version of ReadMemory will try and read memory from the process 1144 // if the process is alive. The order is: 1145 // 1 - if (prefer_file_cache == true) then read from object file cache 1146 // 2 - if there is a valid process, try and read from its memory 1147 // 3 - if (prefer_file_cache == false) then read from object file cache 1148 size_t 1149 ReadMemory (const Address& addr, 1150 bool prefer_file_cache, 1151 void *dst, 1152 size_t dst_len, 1153 Error &error, 1154 lldb::addr_t *load_addr_ptr = NULL); 1155 1156 size_t 1157 ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error); 1158 1159 size_t 1160 ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error); 1161 1162 size_t 1163 ReadScalarIntegerFromMemory (const Address& addr, 1164 bool prefer_file_cache, 1165 uint32_t byte_size, 1166 bool is_signed, 1167 Scalar &scalar, 1168 Error &error); 1169 1170 uint64_t 1171 ReadUnsignedIntegerFromMemory (const Address& addr, 1172 bool prefer_file_cache, 1173 size_t integer_byte_size, 1174 uint64_t fail_value, 1175 Error &error); 1176 1177 bool 1178 ReadPointerFromMemory (const Address& addr, 1179 bool prefer_file_cache, 1180 Error &error, 1181 Address &pointer_addr); 1182 1183 SectionLoadList& GetSectionLoadList()1184 GetSectionLoadList() 1185 { 1186 return m_section_load_history.GetCurrentSectionLoadList(); 1187 } 1188 1189 // const SectionLoadList& 1190 // GetSectionLoadList() const 1191 // { 1192 // return const_cast<SectionLoadHistory *>(&m_section_load_history)->GetCurrentSectionLoadList(); 1193 // } 1194 1195 static Target * 1196 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 1197 const SymbolContext *sc_ptr); 1198 1199 //------------------------------------------------------------------ 1200 // lldb::ExecutionContextScope pure virtual functions 1201 //------------------------------------------------------------------ 1202 virtual lldb::TargetSP 1203 CalculateTarget (); 1204 1205 virtual lldb::ProcessSP 1206 CalculateProcess (); 1207 1208 virtual lldb::ThreadSP 1209 CalculateThread (); 1210 1211 virtual lldb::StackFrameSP 1212 CalculateStackFrame (); 1213 1214 virtual void 1215 CalculateExecutionContext (ExecutionContext &exe_ctx); 1216 1217 PathMappingList & 1218 GetImageSearchPathList (); 1219 1220 ClangASTContext * 1221 GetScratchClangASTContext(bool create_on_demand=true); 1222 1223 ClangASTImporter * 1224 GetClangASTImporter(); 1225 1226 //---------------------------------------------------------------------- 1227 // Install any files through the platform that need be to installed 1228 // prior to launching or attaching. 1229 //---------------------------------------------------------------------- 1230 Error 1231 Install(ProcessLaunchInfo *launch_info); 1232 1233 bool 1234 ResolveFileAddress (lldb::addr_t load_addr, 1235 Address &so_addr); 1236 1237 bool 1238 ResolveLoadAddress (lldb::addr_t load_addr, 1239 Address &so_addr, 1240 uint32_t stop_id = SectionLoadHistory::eStopIDNow); 1241 1242 bool 1243 SetSectionLoadAddress (const lldb::SectionSP §ion, 1244 lldb::addr_t load_addr, 1245 bool warn_multiple = false); 1246 1247 size_t 1248 UnloadModuleSections (const lldb::ModuleSP &module_sp); 1249 1250 size_t 1251 UnloadModuleSections (const ModuleList &module_list); 1252 1253 bool 1254 SetSectionUnloaded (const lldb::SectionSP §ion_sp); 1255 1256 bool 1257 SetSectionUnloaded (const lldb::SectionSP §ion_sp, lldb::addr_t load_addr); 1258 1259 void 1260 ClearAllLoadedSections (); 1261 1262 // Since expressions results can persist beyond the lifetime of a process, 1263 // and the const expression results are available after a process is gone, 1264 // we provide a way for expressions to be evaluated from the Target itself. 1265 // If an expression is going to be run, then it should have a frame filled 1266 // in in th execution context. 1267 lldb::ExpressionResults 1268 EvaluateExpression (const char *expression, 1269 StackFrame *frame, 1270 lldb::ValueObjectSP &result_valobj_sp, 1271 const EvaluateExpressionOptions& options = EvaluateExpressionOptions()); 1272 1273 ClangPersistentVariables & 1274 GetPersistentVariables(); 1275 1276 //------------------------------------------------------------------ 1277 // Target Stop Hooks 1278 //------------------------------------------------------------------ 1279 class StopHook : public UserID 1280 { 1281 public: 1282 ~StopHook (); 1283 1284 StopHook (const StopHook &rhs); 1285 1286 StringList * GetCommandPointer()1287 GetCommandPointer () 1288 { 1289 return &m_commands; 1290 } 1291 1292 const StringList & GetCommands()1293 GetCommands() 1294 { 1295 return m_commands; 1296 } 1297 1298 lldb::TargetSP & GetTarget()1299 GetTarget() 1300 { 1301 return m_target_sp; 1302 } 1303 1304 void SetCommands(StringList & in_commands)1305 SetCommands (StringList &in_commands) 1306 { 1307 m_commands = in_commands; 1308 } 1309 1310 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done. 1311 void 1312 SetSpecifier (SymbolContextSpecifier *specifier); 1313 1314 SymbolContextSpecifier * GetSpecifier()1315 GetSpecifier () 1316 { 1317 return m_specifier_sp.get(); 1318 } 1319 1320 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done. 1321 void 1322 SetThreadSpecifier (ThreadSpec *specifier); 1323 1324 ThreadSpec * GetThreadSpecifier()1325 GetThreadSpecifier() 1326 { 1327 return m_thread_spec_ap.get(); 1328 } 1329 1330 bool IsActive()1331 IsActive() 1332 { 1333 return m_active; 1334 } 1335 1336 void SetIsActive(bool is_active)1337 SetIsActive (bool is_active) 1338 { 1339 m_active = is_active; 1340 } 1341 1342 void 1343 GetDescription (Stream *s, lldb::DescriptionLevel level) const; 1344 1345 private: 1346 lldb::TargetSP m_target_sp; 1347 StringList m_commands; 1348 lldb::SymbolContextSpecifierSP m_specifier_sp; 1349 std::unique_ptr<ThreadSpec> m_thread_spec_ap; 1350 bool m_active; 1351 1352 // Use CreateStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands, 1353 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.) 1354 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid); 1355 friend class Target; 1356 }; 1357 typedef std::shared_ptr<StopHook> StopHookSP; 1358 1359 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook. 1360 // Returns the id of the new hook. 1361 StopHookSP 1362 CreateStopHook (); 1363 1364 void 1365 RunStopHooks (); 1366 1367 size_t 1368 GetStopHookSize(); 1369 1370 bool SetSuppresStopHooks(bool suppress)1371 SetSuppresStopHooks (bool suppress) 1372 { 1373 bool old_value = m_suppress_stop_hooks; 1374 m_suppress_stop_hooks = suppress; 1375 return old_value; 1376 } 1377 1378 bool GetSuppressStopHooks()1379 GetSuppressStopHooks () 1380 { 1381 return m_suppress_stop_hooks; 1382 } 1383 1384 // StopHookSP & 1385 // GetStopHookByIndex (size_t index); 1386 // 1387 bool 1388 RemoveStopHookByID (lldb::user_id_t uid); 1389 1390 void 1391 RemoveAllStopHooks (); 1392 1393 StopHookSP 1394 GetStopHookByID (lldb::user_id_t uid); 1395 1396 bool 1397 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state); 1398 1399 void 1400 SetAllStopHooksActiveState (bool active_state); 1401 GetNumStopHooks()1402 size_t GetNumStopHooks () const 1403 { 1404 return m_stop_hooks.size(); 1405 } 1406 1407 StopHookSP GetStopHookAtIndex(size_t index)1408 GetStopHookAtIndex (size_t index) 1409 { 1410 if (index >= GetNumStopHooks()) 1411 return StopHookSP(); 1412 StopHookCollection::iterator pos = m_stop_hooks.begin(); 1413 1414 while (index > 0) 1415 { 1416 pos++; 1417 index--; 1418 } 1419 return (*pos).second; 1420 } 1421 1422 lldb::PlatformSP GetPlatform()1423 GetPlatform () 1424 { 1425 return m_platform_sp; 1426 } 1427 1428 void SetPlatform(const lldb::PlatformSP & platform_sp)1429 SetPlatform (const lldb::PlatformSP &platform_sp) 1430 { 1431 m_platform_sp = platform_sp; 1432 } 1433 1434 SourceManager & 1435 GetSourceManager (); 1436 1437 ClangModulesDeclVendor * 1438 GetClangModulesDeclVendor (); 1439 1440 //------------------------------------------------------------------ 1441 // Methods. 1442 //------------------------------------------------------------------ 1443 lldb::SearchFilterSP 1444 GetSearchFilterForModule (const FileSpec *containingModule); 1445 1446 lldb::SearchFilterSP 1447 GetSearchFilterForModuleList (const FileSpecList *containingModuleList); 1448 1449 lldb::SearchFilterSP 1450 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles); 1451 1452 protected: 1453 //------------------------------------------------------------------ 1454 // Member variables. 1455 //------------------------------------------------------------------ 1456 Debugger & m_debugger; 1457 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1458 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe 1459 ArchSpec m_arch; 1460 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). 1461 SectionLoadHistory m_section_load_history; 1462 BreakpointList m_breakpoint_list; 1463 BreakpointList m_internal_breakpoint_list; 1464 lldb::BreakpointSP m_last_created_breakpoint; 1465 WatchpointList m_watchpoint_list; 1466 lldb::WatchpointSP m_last_created_watchpoint; 1467 // We want to tightly control the process destruction process so 1468 // we can correctly tear down everything that we need to, so the only 1469 // class that knows about the process lifespan is this target class. 1470 lldb::ProcessSP m_process_sp; 1471 lldb::SearchFilterSP m_search_filter_sp; 1472 PathMappingList m_image_search_paths; 1473 lldb::ClangASTContextUP m_scratch_ast_context_ap; 1474 lldb::ClangASTSourceUP m_scratch_ast_source_ap; 1475 lldb::ClangASTImporterUP m_ast_importer_ap; 1476 lldb::ClangModulesDeclVendorUP m_clang_modules_decl_vendor_ap; 1477 lldb::ClangPersistentVariablesUP m_persistent_variables; ///< These are the persistent variables associated with this process for the expression parser. 1478 1479 lldb::SourceManagerUP m_source_manager_ap; 1480 1481 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1482 StopHookCollection m_stop_hooks; 1483 lldb::user_id_t m_stop_hook_next_id; 1484 bool m_valid; 1485 bool m_suppress_stop_hooks; 1486 bool m_is_dummy_target; 1487 1488 static void 1489 ImageSearchPathsChanged (const PathMappingList &path_list, 1490 void *baton); 1491 1492 private: 1493 DISALLOW_COPY_AND_ASSIGN (Target); 1494 }; 1495 1496 } // namespace lldb_private 1497 1498 #endif // liblldb_Target_h_ 1499