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