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