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