1 //===-- Target.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Target_h_
11 #define liblldb_Target_h_
21 // Other libraries and framework includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/Breakpoint/BreakpointList.h"
25 #include "lldb/Breakpoint/WatchpointList.h"
26 #include "lldb/Core/ArchSpec.h"
27 #include "lldb/Core/Broadcaster.h"
28 #include "lldb/Core/Disassembler.h"
29 #include "lldb/Core/ModuleList.h"
30 #include "lldb/Core/UserSettingsController.h"
31 #include "lldb/Expression/Expression.h"
32 #include "lldb/Symbol/TypeSystem.h"
33 #include "lldb/Target/ExecutionContextScope.h"
34 #include "lldb/Target/PathMappingList.h"
35 #include "lldb/Target/ProcessLaunchInfo.h"
36 #include "lldb/Target/SectionLoadHistory.h"
38 namespace lldb_private {
40 extern OptionEnumValueElement g_dynamic_value_types[];
42 typedef enum InlineStrategy
44 eInlineBreakpointsNever = 0,
45 eInlineBreakpointsHeaders,
46 eInlineBreakpointsAlways
49 typedef enum LoadScriptFromSymFile
51 eLoadScriptFromSymFileTrue,
52 eLoadScriptFromSymFileFalse,
53 eLoadScriptFromSymFileWarn
54 } LoadScriptFromSymFile;
56 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
59 class TargetProperties : public Properties
62 TargetProperties(Target *target);
64 ~TargetProperties() override;
67 GetDefaultArchitecture () const;
70 SetDefaultArchitecture (const ArchSpec& arch);
73 GetMoveToNearestCode () const;
75 lldb::DynamicValueType
76 GetPreferDynamicValue() const;
79 SetPreferDynamicValue (lldb::DynamicValueType d);
82 GetDisableASLR () const;
85 SetDisableASLR (bool b);
88 GetDetachOnError () const;
91 SetDetachOnError (bool b);
94 GetDisableSTDIO () const;
97 SetDisableSTDIO (bool b);
100 GetDisassemblyFlavor() const;
103 // SetDisassemblyFlavor(const char *flavor);
106 GetInlineStrategy () const;
112 SetArg0 (const char *arg);
115 GetRunArguments (Args &args) const;
118 SetRunArguments (const Args &args);
121 GetEnvironmentAsArgs (Args &env) const;
124 SetEnvironmentFromArgs (const Args &env);
127 GetSkipPrologue() const;
130 GetSourcePathMap () const;
133 GetExecutableSearchPaths ();
136 GetDebugFileSearchPaths ();
139 GetClangModuleSearchPaths ();
142 GetEnableAutoImportClangModules () const;
145 GetEnableSyntheticValue () const;
148 GetMaximumNumberOfChildrenToDisplay() const;
151 GetMaximumSizeOfStringSummary() const;
154 GetMaximumMemReadSize () const;
157 GetStandardInputPath () const;
160 SetStandardInputPath (const char *path);
163 GetStandardOutputPath () const;
166 SetStandardOutputPath (const char *path);
169 GetStandardErrorPath () const;
172 SetStandardErrorPath (const char *path);
175 GetBreakpointsConsultPlatformAvoidList ();
178 GetLanguage () const;
181 GetExpressionPrefixContentsAsCString ();
184 GetUseHexImmediates() const;
187 GetUseFastStepping() const;
190 GetDisplayExpressionsInCrashlogs () const;
192 LoadScriptFromSymFile
193 GetLoadScriptFromSymbolFile() const;
195 Disassembler::HexImmediateStyle
196 GetHexImmediateStyle() const;
198 MemoryModuleLoadLevel
199 GetMemoryModuleLoadLevel() const;
202 GetUserSpecifiedTrapHandlerNames (Args &args) const;
205 SetUserSpecifiedTrapHandlerNames (const Args &args);
208 GetNonStopModeEnabled () const;
211 SetNonStopModeEnabled (bool b);
214 GetDisplayRuntimeSupportValues () const;
217 SetDisplayRuntimeSupportValues (bool b);
219 const ProcessLaunchInfo &
220 GetProcessLaunchInfo();
223 SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info);
226 //------------------------------------------------------------------
227 // Callbacks for m_launch_info.
228 //------------------------------------------------------------------
229 static void Arg0ValueChangedCallback(void *target_property_ptr, OptionValue *);
230 static void RunArgsValueChangedCallback(void *target_property_ptr, OptionValue *);
231 static void EnvVarsValueChangedCallback(void *target_property_ptr, OptionValue *);
232 static void InheritEnvValueChangedCallback(void *target_property_ptr, OptionValue *);
233 static void InputPathValueChangedCallback(void *target_property_ptr, OptionValue *);
234 static void OutputPathValueChangedCallback(void *target_property_ptr, OptionValue *);
235 static void ErrorPathValueChangedCallback(void *target_property_ptr, OptionValue *);
236 static void DetachOnErrorValueChangedCallback(void *target_property_ptr, OptionValue *);
237 static void DisableASLRValueChangedCallback(void *target_property_ptr, OptionValue *);
238 static void DisableSTDIOValueChangedCallback(void *target_property_ptr, OptionValue *);
240 //------------------------------------------------------------------
242 //------------------------------------------------------------------
243 ProcessLaunchInfo m_launch_info;
246 class EvaluateExpressionOptions
249 static const uint32_t default_timeout = 500000;
250 EvaluateExpressionOptions() :
251 m_execution_policy(eExecutionPolicyOnlyWhenNeeded),
252 m_language (lldb::eLanguageTypeUnknown),
253 m_prefix (), // A prefix specific to this expression that is added after the prefix from the settings (if any)
254 m_coerce_to_id (false),
255 m_unwind_on_error (true),
256 m_ignore_breakpoints (false),
257 m_keep_in_memory (false),
259 m_stop_others (true),
261 m_trap_exceptions (true),
262 m_generate_debug_info (false),
263 m_result_is_internal (false),
264 m_use_dynamic (lldb::eNoDynamicValues),
265 m_timeout_usec (default_timeout),
266 m_one_thread_timeout_usec (0),
267 m_cancel_callback (nullptr),
268 m_cancel_callback_baton (nullptr)
273 GetExecutionPolicy () const
275 return m_execution_policy;
279 SetExecutionPolicy (ExecutionPolicy policy = eExecutionPolicyAlways)
281 m_execution_policy = policy;
291 SetLanguage(lldb::LanguageType language)
293 m_language = language;
297 DoesCoerceToId () const
299 return m_coerce_to_id;
305 return (m_prefix.empty() ? nullptr : m_prefix.c_str());
309 SetPrefix (const char *prefix)
311 if (prefix && prefix[0])
318 SetCoerceToId (bool coerce = true)
320 m_coerce_to_id = coerce;
324 DoesUnwindOnError () const
326 return m_unwind_on_error;
330 SetUnwindOnError (bool unwind = false)
332 m_unwind_on_error = unwind;
336 DoesIgnoreBreakpoints () const
338 return m_ignore_breakpoints;
342 SetIgnoreBreakpoints (bool ignore = false)
344 m_ignore_breakpoints = ignore;
348 DoesKeepInMemory () const
350 return m_keep_in_memory;
354 SetKeepInMemory (bool keep = true)
356 m_keep_in_memory = keep;
359 lldb::DynamicValueType
360 GetUseDynamic () const
362 return m_use_dynamic;
366 SetUseDynamic (lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget)
368 m_use_dynamic = dynamic;
372 GetTimeoutUsec () const
374 return m_timeout_usec;
378 SetTimeoutUsec (uint32_t timeout = 0)
380 m_timeout_usec = timeout;
384 GetOneThreadTimeoutUsec () const
386 return m_one_thread_timeout_usec;
390 SetOneThreadTimeoutUsec (uint32_t timeout = 0)
392 m_one_thread_timeout_usec = timeout;
396 GetTryAllThreads () const
402 SetTryAllThreads (bool try_others = true)
404 m_try_others = try_others;
408 GetStopOthers () const
410 return m_stop_others;
414 SetStopOthers (bool stop_others = true)
416 m_stop_others = stop_others;
430 m_generate_debug_info = true;
434 GetGenerateDebugInfo() const
436 return m_generate_debug_info;
440 SetGenerateDebugInfo(bool b)
442 m_generate_debug_info = b;
446 GetColorizeErrors () const
448 return m_ansi_color_errors;
452 SetColorizeErrors (bool b)
454 m_ansi_color_errors = b;
458 GetTrapExceptions() const
460 return m_trap_exceptions;
464 SetTrapExceptions (bool b)
466 m_trap_exceptions = b;
470 GetREPLEnabled() const
476 SetREPLEnabled (bool b)
482 SetCancelCallback (lldb::ExpressionCancelCallback callback, void *baton)
484 m_cancel_callback_baton = baton;
485 m_cancel_callback = callback;
489 InvokeCancelCallback (lldb::ExpressionEvaluationPhase phase) const
491 return ((m_cancel_callback != nullptr) ? m_cancel_callback(phase, m_cancel_callback_baton) : false);
494 // Allows the expression contents to be remapped to point to the specified file and line
495 // using #line directives.
497 SetPoundLine (const char *path, uint32_t line) const
501 m_pound_line_file = path;
502 m_pound_line_line = line;
506 m_pound_line_file.clear();
507 m_pound_line_line = 0;
512 GetPoundLineFilePath () const
514 return (m_pound_line_file.empty() ? nullptr : m_pound_line_file.c_str());
518 GetPoundLineLine () const
520 return m_pound_line_line;
524 SetResultIsInternal (bool b)
526 m_result_is_internal = b;
530 GetResultIsInternal () const
532 return m_result_is_internal;
536 ExecutionPolicy m_execution_policy;
537 lldb::LanguageType m_language;
538 std::string m_prefix;
540 bool m_unwind_on_error;
541 bool m_ignore_breakpoints;
542 bool m_keep_in_memory;
546 bool m_trap_exceptions;
548 bool m_generate_debug_info;
549 bool m_ansi_color_errors;
550 bool m_result_is_internal;
551 lldb::DynamicValueType m_use_dynamic;
552 uint32_t m_timeout_usec;
553 uint32_t m_one_thread_timeout_usec;
554 lldb::ExpressionCancelCallback m_cancel_callback;
555 void *m_cancel_callback_baton;
556 // If m_pound_line_file is not empty and m_pound_line_line is non-zero,
557 // use #line %u "%s" before the expression content to remap where the source
559 mutable std::string m_pound_line_file;
560 mutable uint32_t m_pound_line_line;
563 //----------------------------------------------------------------------
565 //----------------------------------------------------------------------
567 public std::enable_shared_from_this<Target>,
568 public TargetProperties,
570 public ExecutionContextScope,
571 public ModuleList::Notifier
574 friend class TargetList;
576 //------------------------------------------------------------------
577 /// Broadcaster event bits definitions.
578 //------------------------------------------------------------------
581 eBroadcastBitBreakpointChanged = (1 << 0),
582 eBroadcastBitModulesLoaded = (1 << 1),
583 eBroadcastBitModulesUnloaded = (1 << 2),
584 eBroadcastBitWatchpointChanged = (1 << 3),
585 eBroadcastBitSymbolsLoaded = (1 << 4)
588 // These two functions fill out the Broadcaster interface:
590 static ConstString &GetStaticBroadcasterClass ();
592 ConstString &GetBroadcasterClass() const override
594 return GetStaticBroadcasterClass();
597 // This event data class is for use by the TargetList to broadcast new target notifications.
598 class TargetEventData : public EventData
601 TargetEventData (const lldb::TargetSP &target_sp);
603 TargetEventData (const lldb::TargetSP &target_sp, const ModuleList &module_list);
605 ~TargetEventData() override;
607 static const ConstString &
611 GetFlavor() const override
613 return TargetEventData::GetFlavorString ();
617 Dump(Stream *s) const override;
619 static const TargetEventData *
620 GetEventDataFromEvent (const Event *event_ptr);
622 static lldb::TargetSP
623 GetTargetFromEvent (const Event *event_ptr);
626 GetModuleListFromEvent (const Event *event_ptr);
628 const lldb::TargetSP &
635 GetModuleList() const
637 return m_module_list;
641 lldb::TargetSP m_target_sp;
642 ModuleList m_module_list;
644 DISALLOW_COPY_AND_ASSIGN (TargetEventData);
650 SettingsInitialize ();
653 SettingsTerminate ();
656 GetDefaultExecutableSearchPaths ();
659 GetDefaultDebugFileSearchPaths ();
662 GetDefaultClangModuleSearchPaths ();
665 GetDefaultArchitecture ();
668 SetDefaultArchitecture (const ArchSpec &arch);
671 // UpdateInstanceName ();
674 GetSharedModule(const ModuleSpec &module_spec,
675 Error *error_ptr = nullptr);
677 //----------------------------------------------------------------------
678 // Settings accessors
679 //----------------------------------------------------------------------
681 static const lldb::TargetPropertiesSP &
682 GetGlobalProperties();
691 DeleteCurrentProcess ();
696 //------------------------------------------------------------------
697 /// Dump a description of this object to a Stream.
699 /// Dump a description of the contents of this object to the
700 /// supplied stream \a s. The dumped content will be only what has
701 /// been loaded or parsed up to this point at which this function
702 /// is called, so this is a good way to see what has been parsed
706 /// The stream to which to dump the object description.
707 //------------------------------------------------------------------
709 Dump (Stream *s, lldb::DescriptionLevel description_level);
711 const lldb::ProcessSP &
712 CreateProcess (Listener &listener,
713 const char *plugin_name,
714 const FileSpec *crash_file);
716 const lldb::ProcessSP &
717 GetProcessSP () const;
729 Launch (ProcessLaunchInfo &launch_info,
730 Stream *stream); // Optional stream to receive first stop info
733 Attach (ProcessAttachInfo &attach_info,
734 Stream *stream); // Optional stream to receive first stop info
736 //------------------------------------------------------------------
737 // This part handles the breakpoints.
738 //------------------------------------------------------------------
741 GetBreakpointList(bool internal = false);
743 const BreakpointList &
744 GetBreakpointList(bool internal = false) const;
747 GetLastCreatedBreakpoint ()
749 return m_last_created_breakpoint;
753 GetBreakpointByID (lldb::break_id_t break_id);
755 // Use this to create a file and line breakpoint to a given module or all module it is nullptr
757 CreateBreakpoint (const FileSpecList *containingModules,
758 const FileSpec &file,
760 LazyBool check_inlines,
761 LazyBool skip_prologue,
763 bool request_hardware,
764 LazyBool move_to_nearest_code);
766 // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list:
768 CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
769 const FileSpecList *source_file_list,
770 RegularExpression &source_regex,
772 bool request_hardware,
773 LazyBool move_to_nearest_code);
775 // Use this to create a breakpoint from a load address
777 CreateBreakpoint (lldb::addr_t load_addr,
779 bool request_hardware);
781 // Use this to create a breakpoint from a load address and a module file spec
783 CreateAddressInModuleBreakpoint (lldb::addr_t file_addr,
785 const FileSpec *file_spec,
786 bool request_hardware);
788 // Use this to create Address breakpoints:
790 CreateBreakpoint (const Address &addr,
792 bool request_hardware);
794 // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is nullptr
795 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target
796 // setting, else we use the values passed in
798 CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
799 const FileSpecList *containingSourceFiles,
800 RegularExpression &func_regexp,
801 lldb::LanguageType requested_language,
802 LazyBool skip_prologue,
804 bool request_hardware);
806 // Use this to create a function breakpoint by name in containingModule, or all modules if it is nullptr
807 // When "skip_prologue is set to eLazyBoolCalculate, we use the current target
808 // setting, else we use the values passed in.
809 // func_name_type_mask is or'ed values from the FunctionNameType enum.
811 CreateBreakpoint (const FileSpecList *containingModules,
812 const FileSpecList *containingSourceFiles,
813 const char *func_name,
814 uint32_t func_name_type_mask,
815 lldb::LanguageType language,
816 LazyBool skip_prologue,
818 bool request_hardware);
821 CreateExceptionBreakpoint(enum lldb::LanguageType language,
825 Args *additional_args = nullptr,
826 Error *additional_args_error = nullptr);
828 // This is the same as the func_name breakpoint except that you can specify a vector of names. This is cheaper
829 // than a regular expression breakpoint in the case where you just want to set a breakpoint on a set of names
831 // func_name_type_mask is or'ed values from the FunctionNameType enum.
833 CreateBreakpoint (const FileSpecList *containingModules,
834 const FileSpecList *containingSourceFiles,
835 const char *func_names[],
837 uint32_t func_name_type_mask,
838 lldb::LanguageType language,
839 LazyBool skip_prologue,
841 bool request_hardware);
844 CreateBreakpoint (const FileSpecList *containingModules,
845 const FileSpecList *containingSourceFiles,
846 const std::vector<std::string> &func_names,
847 uint32_t func_name_type_mask,
848 lldb::LanguageType language,
849 LazyBool skip_prologue,
851 bool request_hardware);
853 // Use this to create a general breakpoint:
855 CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
856 lldb::BreakpointResolverSP &resolver_sp,
858 bool request_hardware,
859 bool resolve_indirect_symbols);
861 // Use this to create a watchpoint:
863 CreateWatchpoint (lldb::addr_t addr,
865 const CompilerType *type,
870 GetLastCreatedWatchpoint ()
872 return m_last_created_watchpoint;
878 return m_watchpoint_list;
882 RemoveAllBreakpoints (bool internal_also = false);
885 DisableAllBreakpoints (bool internal_also = false);
888 EnableAllBreakpoints (bool internal_also = false);
891 DisableBreakpointByID (lldb::break_id_t break_id);
894 EnableBreakpointByID (lldb::break_id_t break_id);
897 RemoveBreakpointByID (lldb::break_id_t break_id);
899 // The flag 'end_to_end', default to true, signifies that the operation is
900 // performed end to end, for both the debugger and the debuggee.
903 RemoveAllWatchpoints (bool end_to_end = true);
906 DisableAllWatchpoints (bool end_to_end = true);
909 EnableAllWatchpoints (bool end_to_end = true);
912 ClearAllWatchpointHitCounts ();
915 ClearAllWatchpointHistoricValues ();
918 IgnoreAllWatchpoints (uint32_t ignore_count);
921 DisableWatchpointByID (lldb::watch_id_t watch_id);
924 EnableWatchpointByID (lldb::watch_id_t watch_id);
927 RemoveWatchpointByID (lldb::watch_id_t watch_id);
930 IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count);
932 //------------------------------------------------------------------
933 /// Get \a load_addr as a callable code load address for this target
935 /// Take \a load_addr and potentially add any address bits that are
936 /// needed to make the address callable. For ARM this can set bit
937 /// zero (if it already isn't) if \a load_addr is a thumb function.
938 /// If \a addr_class is set to eAddressClassInvalid, then the address
939 /// adjustment will always happen. If it is set to an address class
940 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
942 //------------------------------------------------------------------
944 GetCallableLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
946 //------------------------------------------------------------------
947 /// Get \a load_addr as an opcode for this target.
949 /// Take \a load_addr and potentially strip any address bits that are
950 /// needed to make the address point to an opcode. For ARM this can
951 /// clear bit zero (if it already isn't) if \a load_addr is a
952 /// thumb function and load_addr is in code.
953 /// If \a addr_class is set to eAddressClassInvalid, then the address
954 /// adjustment will always happen. If it is set to an address class
955 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
957 //------------------------------------------------------------------
959 GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
961 // Get load_addr as breakable load address for this target.
962 // Take a addr and check if for any reason there is a better address than this to put a breakpoint on.
963 // If there is then return that address.
964 // For MIPS, if instruction at addr is a delay slot instruction then this method will find the address of its
965 // previous instruction and return that address.
967 GetBreakableLoadAddress (lldb::addr_t addr);
970 ModulesDidLoad (ModuleList &module_list);
973 ModulesDidUnload (ModuleList &module_list, bool delete_locations);
976 SymbolsDidLoad (ModuleList &module_list);
979 ClearModules(bool delete_locations);
981 //------------------------------------------------------------------
982 /// Called as the last function in Process::DidExec().
984 /// Process::DidExec() will clear a lot of state in the process,
985 /// then try to reload a dynamic loader plugin to discover what
986 /// binaries are currently available and then this function should
987 /// be called to allow the target to do any cleanup after everything
988 /// has been figured out. It can remove breakpoints that no longer
989 /// make sense as the exec might have changed the target
990 /// architecture, and unloaded some modules that might get deleted.
991 //------------------------------------------------------------------
995 //------------------------------------------------------------------
996 /// Gets the module for the main executable.
998 /// Each process has a notion of a main executable that is the file
999 /// that will be executed or attached to. Executable files can have
1000 /// dependent modules that are discovered from the object files, or
1001 /// discovered at runtime as things are dynamically loaded.
1004 /// The shared pointer to the executable module which can
1005 /// contains a nullptr Module object if no executable has been
1008 /// @see DynamicLoader
1009 /// @see ObjectFile::GetDependentModules (FileSpecList&)
1010 /// @see Process::SetExecutableModule(lldb::ModuleSP&)
1011 //------------------------------------------------------------------
1013 GetExecutableModule ();
1016 GetExecutableModulePointer ();
1018 //------------------------------------------------------------------
1019 /// Set the main executable module.
1021 /// Each process has a notion of a main executable that is the file
1022 /// that will be executed or attached to. Executable files can have
1023 /// dependent modules that are discovered from the object files, or
1024 /// discovered at runtime as things are dynamically loaded.
1026 /// Setting the executable causes any of the current dependant
1027 /// image information to be cleared and replaced with the static
1028 /// dependent image information found by calling
1029 /// ObjectFile::GetDependentModules (FileSpecList&) on the main
1030 /// executable and any modules on which it depends. Calling
1031 /// Process::GetImages() will return the newly found images that
1032 /// were obtained from all of the object files.
1034 /// @param[in] module_sp
1035 /// A shared pointer reference to the module that will become
1036 /// the main executable for this process.
1038 /// @param[in] get_dependent_files
1039 /// If \b true then ask the object files to track down any
1040 /// known dependent files.
1042 /// @see ObjectFile::GetDependentModules (FileSpecList&)
1043 /// @see Process::GetImages()
1044 //------------------------------------------------------------------
1046 SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
1049 LoadScriptingResources(std::list<Error>& errors,
1050 Stream* feedback_stream = nullptr,
1051 bool continue_on_error = true)
1053 return m_images.LoadScriptingResourcesInTarget(this,errors,feedback_stream,continue_on_error);
1056 //------------------------------------------------------------------
1057 /// Get accessor for the images for this process.
1059 /// Each process has a notion of a main executable that is the file
1060 /// that will be executed or attached to. Executable files can have
1061 /// dependent modules that are discovered from the object files, or
1062 /// discovered at runtime as things are dynamically loaded. After
1063 /// a main executable has been set, the images will contain a list
1064 /// of all the files that the executable depends upon as far as the
1065 /// object files know. These images will usually contain valid file
1066 /// virtual addresses only. When the process is launched or attached
1067 /// to, the DynamicLoader plug-in will discover where these images
1068 /// were loaded in memory and will resolve the load virtual
1069 /// addresses is each image, and also in images that are loaded by
1073 /// A list of Module objects in a module list.
1074 //------------------------------------------------------------------
1087 //------------------------------------------------------------------
1088 /// Return whether this FileSpec corresponds to a module that should be considered for general searches.
1090 /// This API will be consulted by the SearchFilterForUnconstrainedSearches
1091 /// and any module that returns \b true will not be searched. Note the
1092 /// SearchFilterForUnconstrainedSearches is the search filter that
1093 /// gets used in the CreateBreakpoint calls when no modules is provided.
1095 /// The target call at present just consults the Platform's call of the
1098 /// @param[in] module_sp
1099 /// A shared pointer reference to the module that checked.
1101 /// @return \b true if the module should be excluded, \b false otherwise.
1102 //------------------------------------------------------------------
1104 ModuleIsExcludedForUnconstrainedSearches (const FileSpec &module_spec);
1106 //------------------------------------------------------------------
1107 /// Return whether this module should be considered for general searches.
1109 /// This API will be consulted by the SearchFilterForUnconstrainedSearches
1110 /// and any module that returns \b true will not be searched. Note the
1111 /// SearchFilterForUnconstrainedSearches is the search filter that
1112 /// gets used in the CreateBreakpoint calls when no modules is provided.
1114 /// The target call at present just consults the Platform's call of the
1117 /// FIXME: When we get time we should add a way for the user to set modules that they
1118 /// don't want searched, in addition to or instead of the platform ones.
1120 /// @param[in] module_sp
1121 /// A shared pointer reference to the module that checked.
1123 /// @return \b true if the module should be excluded, \b false otherwise.
1124 //------------------------------------------------------------------
1126 ModuleIsExcludedForUnconstrainedSearches (const lldb::ModuleSP &module_sp);
1129 GetArchitecture () const
1134 //------------------------------------------------------------------
1135 /// Set the architecture for this target.
1137 /// If the current target has no Images read in, then this just sets the architecture, which will
1138 /// be used to select the architecture of the ExecutableModule when that is set.
1139 /// If the current target has an ExecutableModule, then calling SetArchitecture with a different
1140 /// architecture from the currently selected one will reset the ExecutableModule to that slice
1141 /// of the file backing the ExecutableModule. If the file backing the ExecutableModule does not
1142 /// contain a fork of this architecture, then this code will return false, and the architecture
1143 /// won't be changed.
1144 /// If the input arch_spec is the same as the already set architecture, this is a no-op.
1146 /// @param[in] arch_spec
1147 /// The new architecture.
1150 /// \b true if the architecture was successfully set, \bfalse otherwise.
1151 //------------------------------------------------------------------
1153 SetArchitecture (const ArchSpec &arch_spec);
1156 MergeArchitecture (const ArchSpec &arch_spec);
1165 ReadMemoryFromFileCache (const Address& addr,
1170 // Reading memory through the target allows us to skip going to the process
1171 // for reading memory if possible and it allows us to try and read from
1172 // any constant sections in our object files on disk. If you always want
1173 // live program memory, read straight from the process. If you possibly
1174 // want to read from const sections in object files, read from the target.
1175 // This version of ReadMemory will try and read memory from the process
1176 // if the process is alive. The order is:
1177 // 1 - if (prefer_file_cache == true) then read from object file cache
1178 // 2 - if there is a valid process, try and read from its memory
1179 // 3 - if (prefer_file_cache == false) then read from object file cache
1181 ReadMemory(const Address& addr,
1182 bool prefer_file_cache,
1186 lldb::addr_t *load_addr_ptr = nullptr);
1189 ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error);
1192 ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error);
1195 ReadScalarIntegerFromMemory (const Address& addr,
1196 bool prefer_file_cache,
1203 ReadUnsignedIntegerFromMemory (const Address& addr,
1204 bool prefer_file_cache,
1205 size_t integer_byte_size,
1206 uint64_t fail_value,
1210 ReadPointerFromMemory (const Address& addr,
1211 bool prefer_file_cache,
1213 Address &pointer_addr);
1216 GetSectionLoadList()
1218 return m_section_load_history.GetCurrentSectionLoadList();
1221 // const SectionLoadList&
1222 // GetSectionLoadList() const
1224 // return const_cast<SectionLoadHistory *>(&m_section_load_history)->GetCurrentSectionLoadList();
1228 GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr,
1229 const SymbolContext *sc_ptr);
1231 //------------------------------------------------------------------
1232 // lldb::ExecutionContextScope pure virtual functions
1233 //------------------------------------------------------------------
1235 CalculateTarget() override;
1238 CalculateProcess() override;
1241 CalculateThread() override;
1244 CalculateStackFrame() override;
1247 CalculateExecutionContext(ExecutionContext &exe_ctx) override;
1250 GetImageSearchPathList ();
1253 GetScratchTypeSystemForLanguage (Error *error, lldb::LanguageType language, bool create_on_demand = true);
1255 PersistentExpressionState *
1256 GetPersistentExpressionStateForLanguage (lldb::LanguageType language);
1258 // Creates a UserExpression for the given language, the rest of the parameters have the
1259 // same meaning as for the UserExpression constructor.
1260 // Returns a new-ed object which the caller owns.
1263 GetUserExpressionForLanguage(const char *expr,
1264 const char *expr_prefix,
1265 lldb::LanguageType language,
1266 Expression::ResultType desired_type,
1267 const EvaluateExpressionOptions &options,
1270 // Creates a FunctionCaller for the given language, the rest of the parameters have the
1271 // same meaning as for the FunctionCaller constructor. Since a FunctionCaller can't be
1272 // IR Interpreted, it makes no sense to call this with an ExecutionContextScope that lacks
1274 // Returns a new-ed object which the caller owns.
1277 GetFunctionCallerForLanguage (lldb::LanguageType language,
1278 const CompilerType &return_type,
1279 const Address& function_address,
1280 const ValueList &arg_value_list,
1284 // Creates a UtilityFunction for the given language, the rest of the parameters have the
1285 // same meaning as for the UtilityFunction constructor.
1286 // Returns a new-ed object which the caller owns.
1289 GetUtilityFunctionForLanguage (const char *expr,
1290 lldb::LanguageType language,
1295 GetScratchClangASTContext(bool create_on_demand=true);
1297 lldb::ClangASTImporterSP
1298 GetClangASTImporter();
1300 //----------------------------------------------------------------------
1301 // Install any files through the platform that need be to installed
1302 // prior to launching or attaching.
1303 //----------------------------------------------------------------------
1305 Install(ProcessLaunchInfo *launch_info);
1308 ResolveFileAddress (lldb::addr_t load_addr,
1312 ResolveLoadAddress (lldb::addr_t load_addr,
1314 uint32_t stop_id = SectionLoadHistory::eStopIDNow);
1317 SetSectionLoadAddress (const lldb::SectionSP §ion,
1318 lldb::addr_t load_addr,
1319 bool warn_multiple = false);
1322 UnloadModuleSections (const lldb::ModuleSP &module_sp);
1325 UnloadModuleSections (const ModuleList &module_list);
1328 SetSectionUnloaded (const lldb::SectionSP §ion_sp);
1331 SetSectionUnloaded (const lldb::SectionSP §ion_sp, lldb::addr_t load_addr);
1334 ClearAllLoadedSections ();
1336 // Since expressions results can persist beyond the lifetime of a process,
1337 // and the const expression results are available after a process is gone,
1338 // we provide a way for expressions to be evaluated from the Target itself.
1339 // If an expression is going to be run, then it should have a frame filled
1340 // in in th execution context.
1341 lldb::ExpressionResults
1342 EvaluateExpression (const char *expression,
1343 ExecutionContextScope *exe_scope,
1344 lldb::ValueObjectSP &result_valobj_sp,
1345 const EvaluateExpressionOptions& options = EvaluateExpressionOptions());
1347 lldb::ExpressionVariableSP
1348 GetPersistentVariable(const ConstString &name);
1351 GetPersistentSymbol(const ConstString &name);
1353 //------------------------------------------------------------------
1354 // Target Stop Hooks
1355 //------------------------------------------------------------------
1356 class StopHook : public UserID
1359 StopHook (const StopHook &rhs);
1364 GetCommandPointer ()
1382 SetCommands (StringList &in_commands)
1384 m_commands = in_commands;
1387 // Set the specifier. The stop hook will own the specifier, and is responsible for deleting it when we're done.
1389 SetSpecifier (SymbolContextSpecifier *specifier);
1391 SymbolContextSpecifier *
1394 return m_specifier_sp.get();
1397 // Set the Thread Specifier. The stop hook will own the thread specifier, and is responsible for deleting it when we're done.
1399 SetThreadSpecifier (ThreadSpec *specifier);
1402 GetThreadSpecifier()
1404 return m_thread_spec_ap.get();
1414 SetIsActive (bool is_active)
1416 m_active = is_active;
1420 GetDescription (Stream *s, lldb::DescriptionLevel level) const;
1423 lldb::TargetSP m_target_sp;
1424 StringList m_commands;
1425 lldb::SymbolContextSpecifierSP m_specifier_sp;
1426 std::unique_ptr<ThreadSpec> m_thread_spec_ap;
1429 // Use CreateStopHook to make a new empty stop hook. The GetCommandPointer and fill it with commands,
1430 // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.)
1431 StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid);
1432 friend class Target;
1434 typedef std::shared_ptr<StopHook> StopHookSP;
1436 // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook.
1437 // Returns the id of the new hook.
1448 SetSuppresStopHooks (bool suppress)
1450 bool old_value = m_suppress_stop_hooks;
1451 m_suppress_stop_hooks = suppress;
1456 GetSuppressStopHooks ()
1458 return m_suppress_stop_hooks;
1462 // GetStopHookByIndex (size_t index);
1465 RemoveStopHookByID (lldb::user_id_t uid);
1468 RemoveAllStopHooks ();
1471 GetStopHookByID (lldb::user_id_t uid);
1474 SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state);
1477 SetAllStopHooksActiveState (bool active_state);
1479 size_t GetNumStopHooks () const
1481 return m_stop_hooks.size();
1485 GetStopHookAtIndex (size_t index)
1487 if (index >= GetNumStopHooks())
1488 return StopHookSP();
1489 StopHookCollection::iterator pos = m_stop_hooks.begin();
1496 return (*pos).second;
1502 return m_platform_sp;
1506 SetPlatform (const lldb::PlatformSP &platform_sp)
1508 m_platform_sp = platform_sp;
1512 GetSourceManager ();
1514 ClangModulesDeclVendor *
1515 GetClangModulesDeclVendor ();
1517 //------------------------------------------------------------------
1519 //------------------------------------------------------------------
1520 lldb::SearchFilterSP
1521 GetSearchFilterForModule (const FileSpec *containingModule);
1523 lldb::SearchFilterSP
1524 GetSearchFilterForModuleList (const FileSpecList *containingModuleList);
1526 lldb::SearchFilterSP
1527 GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles);
1530 GetREPL (Error &err, lldb::LanguageType language, const char *repl_options, bool can_create);
1533 SetREPL (lldb::LanguageType language, lldb::REPLSP repl_sp);
1536 //------------------------------------------------------------------
1537 /// Implementing of ModuleList::Notifier.
1538 //------------------------------------------------------------------
1541 ModuleAdded(const ModuleList& module_list, const lldb::ModuleSP& module_sp) override;
1544 ModuleRemoved(const ModuleList& module_list, const lldb::ModuleSP& module_sp) override;
1547 ModuleUpdated(const ModuleList& module_list,
1548 const lldb::ModuleSP& old_module_sp,
1549 const lldb::ModuleSP& new_module_sp) override;
1551 WillClearList(const ModuleList& module_list) override;
1553 //------------------------------------------------------------------
1554 // Member variables.
1555 //------------------------------------------------------------------
1556 Debugger & m_debugger;
1557 lldb::PlatformSP m_platform_sp; ///< The platform for this target.
1558 Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe
1560 ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded).
1561 SectionLoadHistory m_section_load_history;
1562 BreakpointList m_breakpoint_list;
1563 BreakpointList m_internal_breakpoint_list;
1564 lldb::BreakpointSP m_last_created_breakpoint;
1565 WatchpointList m_watchpoint_list;
1566 lldb::WatchpointSP m_last_created_watchpoint;
1567 // We want to tightly control the process destruction process so
1568 // we can correctly tear down everything that we need to, so the only
1569 // class that knows about the process lifespan is this target class.
1570 lldb::ProcessSP m_process_sp;
1571 lldb::SearchFilterSP m_search_filter_sp;
1572 PathMappingList m_image_search_paths;
1573 TypeSystemMap m_scratch_type_system_map;
1575 typedef std::map<lldb::LanguageType, lldb::REPLSP> REPLMap;
1578 lldb::ClangASTImporterSP m_ast_importer_sp;
1579 lldb::ClangModulesDeclVendorUP m_clang_modules_decl_vendor_ap;
1581 lldb::SourceManagerUP m_source_manager_ap;
1583 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
1584 StopHookCollection m_stop_hooks;
1585 lldb::user_id_t m_stop_hook_next_id;
1587 bool m_suppress_stop_hooks;
1588 bool m_is_dummy_target;
1591 ImageSearchPathsChanged (const PathMappingList &path_list,
1595 //------------------------------------------------------------------
1596 /// Construct with optional file and arch.
1598 /// This member is private. Clients must use
1599 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
1600 /// so all targets can be tracked from the central target list.
1602 /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
1603 //------------------------------------------------------------------
1604 Target (Debugger &debugger,
1605 const ArchSpec &target_arch,
1606 const lldb::PlatformSP &platform_sp,
1607 bool is_dummy_target);
1613 // Copy breakpoints, stop hooks and so forth from the dummy target:
1615 PrimeFromDummyTarget(Target *dummy_target);
1618 AddBreakpoint(lldb::BreakpointSP breakpoint_sp, bool internal);
1620 DISALLOW_COPY_AND_ASSIGN (Target);
1623 } // namespace lldb_private
1625 #endif // liblldb_Target_h_