Target.h revision 9e376625d6354d77cd6240007f0d42034dd3f1ee
16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//===-- Target.h ------------------------------------------------*- C++ -*-===//
26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// License. See LICENSE.TXT for details.
76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//
86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)//===----------------------------------------------------------------------===//
96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#ifndef liblldb_Target_h_
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define liblldb_Target_h_
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// C Includes
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// C++ Includes
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Other libraries and framework includes
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Project includes
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "lldb/lldb-public.h"
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "lldb/Breakpoint/BreakpointList.h"
206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#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                      const ClangASTType *type,
526                      uint32_t kind,
527                      Error &error);
528
529    lldb::WatchpointSP
530    GetLastCreatedWatchpoint ()
531    {
532        return m_last_created_watchpoint;
533    }
534
535    WatchpointList &
536    GetWatchpointList()
537    {
538        return m_watchpoint_list;
539    }
540
541    void
542    RemoveAllBreakpoints (bool internal_also = false);
543
544    void
545    DisableAllBreakpoints (bool internal_also = false);
546
547    void
548    EnableAllBreakpoints (bool internal_also = false);
549
550    bool
551    DisableBreakpointByID (lldb::break_id_t break_id);
552
553    bool
554    EnableBreakpointByID (lldb::break_id_t break_id);
555
556    bool
557    RemoveBreakpointByID (lldb::break_id_t break_id);
558
559    // The flag 'end_to_end', default to true, signifies that the operation is
560    // performed end to end, for both the debugger and the debuggee.
561
562    bool
563    RemoveAllWatchpoints (bool end_to_end = true);
564
565    bool
566    DisableAllWatchpoints (bool end_to_end = true);
567
568    bool
569    EnableAllWatchpoints (bool end_to_end = true);
570
571    bool
572    ClearAllWatchpointHitCounts ();
573
574    bool
575    IgnoreAllWatchpoints (uint32_t ignore_count);
576
577    bool
578    DisableWatchpointByID (lldb::watch_id_t watch_id);
579
580    bool
581    EnableWatchpointByID (lldb::watch_id_t watch_id);
582
583    bool
584    RemoveWatchpointByID (lldb::watch_id_t watch_id);
585
586    bool
587    IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count);
588
589    void
590    ModulesDidLoad (ModuleList &module_list);
591
592    void
593    ModulesDidUnload (ModuleList &module_list);
594
595
596    //------------------------------------------------------------------
597    /// Get \a load_addr as a callable code load address for this target
598    ///
599    /// Take \a load_addr and potentially add any address bits that are
600    /// needed to make the address callable. For ARM this can set bit
601    /// zero (if it already isn't) if \a load_addr is a thumb function.
602    /// If \a addr_class is set to eAddressClassInvalid, then the address
603    /// adjustment will always happen. If it is set to an address class
604    /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
605    /// returned.
606    //------------------------------------------------------------------
607    lldb::addr_t
608    GetCallableLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
609
610    //------------------------------------------------------------------
611    /// Get \a load_addr as an opcode for this target.
612    ///
613    /// Take \a load_addr and potentially strip any address bits that are
614    /// needed to make the address point to an opcode. For ARM this can
615    /// clear bit zero (if it already isn't) if \a load_addr is a
616    /// thumb function and load_addr is in code.
617    /// If \a addr_class is set to eAddressClassInvalid, then the address
618    /// adjustment will always happen. If it is set to an address class
619    /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
620    /// returned.
621    //------------------------------------------------------------------
622    lldb::addr_t
623    GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
624
625protected:
626    void
627    ModuleAdded (lldb::ModuleSP &module_sp);
628
629    void
630    ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp);
631
632public:
633    //------------------------------------------------------------------
634    /// Gets the module for the main executable.
635    ///
636    /// Each process has a notion of a main executable that is the file
637    /// that will be executed or attached to. Executable files can have
638    /// dependent modules that are discovered from the object files, or
639    /// discovered at runtime as things are dynamically loaded.
640    ///
641    /// @return
642    ///     The shared pointer to the executable module which can
643    ///     contains a NULL Module object if no executable has been
644    ///     set.
645    ///
646    /// @see DynamicLoader
647    /// @see ObjectFile::GetDependentModules (FileSpecList&)
648    /// @see Process::SetExecutableModule(lldb::ModuleSP&)
649    //------------------------------------------------------------------
650    lldb::ModuleSP
651    GetExecutableModule ();
652
653    Module*
654    GetExecutableModulePointer ();
655
656    //------------------------------------------------------------------
657    /// Set the main executable module.
658    ///
659    /// Each process has a notion of a main executable that is the file
660    /// that will be executed or attached to. Executable files can have
661    /// dependent modules that are discovered from the object files, or
662    /// discovered at runtime as things are dynamically loaded.
663    ///
664    /// Setting the executable causes any of the current dependant
665    /// image information to be cleared and replaced with the static
666    /// dependent image information found by calling
667    /// ObjectFile::GetDependentModules (FileSpecList&) on the main
668    /// executable and any modules on which it depends. Calling
669    /// Process::GetImages() will return the newly found images that
670    /// were obtained from all of the object files.
671    ///
672    /// @param[in] module_sp
673    ///     A shared pointer reference to the module that will become
674    ///     the main executable for this process.
675    ///
676    /// @param[in] get_dependent_files
677    ///     If \b true then ask the object files to track down any
678    ///     known dependent files.
679    ///
680    /// @see ObjectFile::GetDependentModules (FileSpecList&)
681    /// @see Process::GetImages()
682    //------------------------------------------------------------------
683    void
684    SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
685
686    //------------------------------------------------------------------
687    /// Get accessor for the images for this process.
688    ///
689    /// Each process has a notion of a main executable that is the file
690    /// that will be executed or attached to. Executable files can have
691    /// dependent modules that are discovered from the object files, or
692    /// discovered at runtime as things are dynamically loaded. After
693    /// a main executable has been set, the images will contain a list
694    /// of all the files that the executable depends upon as far as the
695    /// object files know. These images will usually contain valid file
696    /// virtual addresses only. When the process is launched or attached
697    /// to, the DynamicLoader plug-in will discover where these images
698    /// were loaded in memory and will resolve the load virtual
699    /// addresses is each image, and also in images that are loaded by
700    /// code.
701    ///
702    /// @return
703    ///     A list of Module objects in a module list.
704    //------------------------------------------------------------------
705    ModuleList&
706    GetImages ()
707    {
708        return m_images;
709    }
710
711    const ModuleList&
712    GetImages () const
713    {
714        return m_images;
715    }
716
717
718    //------------------------------------------------------------------
719    /// Return whether this FileSpec corresponds to a module that should be considered for general searches.
720    ///
721    /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
722    /// and any module that returns \b true will not be searched.  Note the
723    /// SearchFilterForNonModuleSpecificSearches is the search filter that
724    /// gets used in the CreateBreakpoint calls when no modules is provided.
725    ///
726    /// The target call at present just consults the Platform's call of the
727    /// same name.
728    ///
729    /// @param[in] module_sp
730    ///     A shared pointer reference to the module that checked.
731    ///
732    /// @return \b true if the module should be excluded, \b false otherwise.
733    //------------------------------------------------------------------
734    bool
735    ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec);
736
737    //------------------------------------------------------------------
738    /// Return whether this module should be considered for general searches.
739    ///
740    /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
741    /// and any module that returns \b true will not be searched.  Note the
742    /// SearchFilterForNonModuleSpecificSearches is the search filter that
743    /// gets used in the CreateBreakpoint calls when no modules is provided.
744    ///
745    /// The target call at present just consults the Platform's call of the
746    /// same name.
747    ///
748    /// FIXME: When we get time we should add a way for the user to set modules that they
749    /// don't want searched, in addition to or instead of the platform ones.
750    ///
751    /// @param[in] module_sp
752    ///     A shared pointer reference to the module that checked.
753    ///
754    /// @return \b true if the module should be excluded, \b false otherwise.
755    //------------------------------------------------------------------
756    bool
757    ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp);
758
759    ArchSpec &
760    GetArchitecture ()
761    {
762        return m_arch;
763    }
764
765    const ArchSpec &
766    GetArchitecture () const
767    {
768        return m_arch;
769    }
770
771    //------------------------------------------------------------------
772    /// Set the architecture for this target.
773    ///
774    /// If the current target has no Images read in, then this just sets the architecture, which will
775    /// be used to select the architecture of the ExecutableModule when that is set.
776    /// If the current target has an ExecutableModule, then calling SetArchitecture with a different
777    /// architecture from the currently selected one will reset the ExecutableModule to that slice
778    /// of the file backing the ExecutableModule.  If the file backing the ExecutableModule does not
779    /// contain a fork of this architecture, then this code will return false, and the architecture
780    /// won't be changed.
781    /// If the input arch_spec is the same as the already set architecture, this is a no-op.
782    ///
783    /// @param[in] arch_spec
784    ///     The new architecture.
785    ///
786    /// @return
787    ///     \b true if the architecture was successfully set, \bfalse otherwise.
788    //------------------------------------------------------------------
789    bool
790    SetArchitecture (const ArchSpec &arch_spec);
791
792    Debugger &
793    GetDebugger ()
794    {
795        return m_debugger;
796    }
797
798    size_t
799    ReadMemoryFromFileCache (const Address& addr,
800                             void *dst,
801                             size_t dst_len,
802                             Error &error);
803
804    // Reading memory through the target allows us to skip going to the process
805    // for reading memory if possible and it allows us to try and read from
806    // any constant sections in our object files on disk. If you always want
807    // live program memory, read straight from the process. If you possibly
808    // want to read from const sections in object files, read from the target.
809    // This version of ReadMemory will try and read memory from the process
810    // if the process is alive. The order is:
811    // 1 - if (prefer_file_cache == true) then read from object file cache
812    // 2 - if there is a valid process, try and read from its memory
813    // 3 - if (prefer_file_cache == false) then read from object file cache
814    size_t
815    ReadMemory (const Address& addr,
816                bool prefer_file_cache,
817                void *dst,
818                size_t dst_len,
819                Error &error,
820                lldb::addr_t *load_addr_ptr = NULL);
821
822    size_t
823    ReadScalarIntegerFromMemory (const Address& addr,
824                                 bool prefer_file_cache,
825                                 uint32_t byte_size,
826                                 bool is_signed,
827                                 Scalar &scalar,
828                                 Error &error);
829
830    uint64_t
831    ReadUnsignedIntegerFromMemory (const Address& addr,
832                                   bool prefer_file_cache,
833                                   size_t integer_byte_size,
834                                   uint64_t fail_value,
835                                   Error &error);
836
837    bool
838    ReadPointerFromMemory (const Address& addr,
839                           bool prefer_file_cache,
840                           Error &error,
841                           Address &pointer_addr);
842
843    SectionLoadList&
844    GetSectionLoadList()
845    {
846        return m_section_load_list;
847    }
848
849    const SectionLoadList&
850    GetSectionLoadList() const
851    {
852        return m_section_load_list;
853    }
854
855    static Target *
856    GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr,
857                           const SymbolContext *sc_ptr);
858
859    //------------------------------------------------------------------
860    // lldb::ExecutionContextScope pure virtual functions
861    //------------------------------------------------------------------
862    virtual lldb::TargetSP
863    CalculateTarget ();
864
865    virtual lldb::ProcessSP
866    CalculateProcess ();
867
868    virtual lldb::ThreadSP
869    CalculateThread ();
870
871    virtual lldb::StackFrameSP
872    CalculateStackFrame ();
873
874    virtual void
875    CalculateExecutionContext (ExecutionContext &exe_ctx);
876
877    PathMappingList &
878    GetImageSearchPathList ();
879
880    ClangASTContext *
881    GetScratchClangASTContext(bool create_on_demand=true);
882
883    ClangASTImporter *
884    GetClangASTImporter();
885
886
887    // Since expressions results can persist beyond the lifetime of a process,
888    // and the const expression results are available after a process is gone,
889    // we provide a way for expressions to be evaluated from the Target itself.
890    // If an expression is going to be run, then it should have a frame filled
891    // in in th execution context.
892    ExecutionResults
893    EvaluateExpression (const char *expression,
894                        StackFrame *frame,
895                        lldb::ValueObjectSP &result_valobj_sp,
896                        const EvaluateExpressionOptions& options = EvaluateExpressionOptions());
897
898    ClangPersistentVariables &
899    GetPersistentVariables()
900    {
901        return m_persistent_variables;
902    }
903
904    //------------------------------------------------------------------
905    // Target Stop Hooks
906    //------------------------------------------------------------------
907    class StopHook : public UserID
908    {
909    public:
910        ~StopHook ();
911
912        StopHook (const StopHook &rhs);
913
914        StringList *
915        GetCommandPointer ()
916        {
917            return &m_commands;
918        }
919
920        const StringList &
921        GetCommands()
922        {
923            return m_commands;
924        }
925
926        lldb::TargetSP &
927        GetTarget()
928        {
929            return m_target_sp;
930        }
931
932        void
933        SetCommands (StringList &in_commands)
934        {
935            m_commands = in_commands;
936        }
937
938        // Set the specifier.  The stop hook will own the specifier, and is responsible for deleting it when we're done.
939        void
940        SetSpecifier (SymbolContextSpecifier *specifier)
941        {
942            m_specifier_sp.reset (specifier);
943        }
944
945        SymbolContextSpecifier *
946        GetSpecifier ()
947        {
948            return m_specifier_sp.get();
949        }
950
951        // Set the Thread Specifier.  The stop hook will own the thread specifier, and is responsible for deleting it when we're done.
952        void
953        SetThreadSpecifier (ThreadSpec *specifier);
954
955        ThreadSpec *
956        GetThreadSpecifier()
957        {
958            return m_thread_spec_ap.get();
959        }
960
961        bool
962        IsActive()
963        {
964            return m_active;
965        }
966
967        void
968        SetIsActive (bool is_active)
969        {
970            m_active = is_active;
971        }
972
973        void
974        GetDescription (Stream *s, lldb::DescriptionLevel level) const;
975
976    private:
977        lldb::TargetSP m_target_sp;
978        StringList   m_commands;
979        lldb::SymbolContextSpecifierSP m_specifier_sp;
980        std::auto_ptr<ThreadSpec> m_thread_spec_ap;
981        bool m_active;
982
983        // Use AddStopHook to make a new empty stop hook.  The GetCommandPointer and fill it with commands,
984        // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.)
985        StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid);
986        friend class Target;
987    };
988    typedef STD_SHARED_PTR(StopHook) StopHookSP;
989
990    // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook.
991    // Returns the id of the new hook.
992    lldb::user_id_t
993    AddStopHook (StopHookSP &new_hook);
994
995    void
996    RunStopHooks ();
997
998    size_t
999    GetStopHookSize();
1000
1001    bool
1002    SetSuppresStopHooks (bool suppress)
1003    {
1004        bool old_value = m_suppress_stop_hooks;
1005        m_suppress_stop_hooks = suppress;
1006        return old_value;
1007    }
1008
1009    bool
1010    GetSuppressStopHooks ()
1011    {
1012        return m_suppress_stop_hooks;
1013    }
1014
1015    bool
1016    SetSuppressSyntheticValue (bool suppress)
1017    {
1018        bool old_value = m_suppress_synthetic_value;
1019        m_suppress_synthetic_value = suppress;
1020        return old_value;
1021    }
1022
1023    bool
1024    GetSuppressSyntheticValue ()
1025    {
1026        return m_suppress_synthetic_value;
1027    }
1028
1029//    StopHookSP &
1030//    GetStopHookByIndex (size_t index);
1031//
1032    bool
1033    RemoveStopHookByID (lldb::user_id_t uid);
1034
1035    void
1036    RemoveAllStopHooks ();
1037
1038    StopHookSP
1039    GetStopHookByID (lldb::user_id_t uid);
1040
1041    bool
1042    SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state);
1043
1044    void
1045    SetAllStopHooksActiveState (bool active_state);
1046
1047    size_t GetNumStopHooks () const
1048    {
1049        return m_stop_hooks.size();
1050    }
1051
1052    StopHookSP
1053    GetStopHookAtIndex (size_t index)
1054    {
1055        if (index >= GetNumStopHooks())
1056            return StopHookSP();
1057        StopHookCollection::iterator pos = m_stop_hooks.begin();
1058
1059        while (index > 0)
1060        {
1061            pos++;
1062            index--;
1063        }
1064        return (*pos).second;
1065    }
1066
1067    lldb::PlatformSP
1068    GetPlatform ()
1069    {
1070        return m_platform_sp;
1071    }
1072
1073    void
1074    SetPlatform (const lldb::PlatformSP &platform_sp)
1075    {
1076        m_platform_sp = platform_sp;
1077    }
1078
1079    SourceManager &
1080    GetSourceManager ()
1081    {
1082        return m_source_manager;
1083    }
1084
1085    //------------------------------------------------------------------
1086    // Methods.
1087    //------------------------------------------------------------------
1088    lldb::SearchFilterSP
1089    GetSearchFilterForModule (const FileSpec *containingModule);
1090
1091    lldb::SearchFilterSP
1092    GetSearchFilterForModuleList (const FileSpecList *containingModuleList);
1093
1094    lldb::SearchFilterSP
1095    GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles);
1096
1097protected:
1098    //------------------------------------------------------------------
1099    // Member variables.
1100    //------------------------------------------------------------------
1101    Debugger &      m_debugger;
1102    lldb::PlatformSP m_platform_sp;     ///< The platform for this target.
1103    Mutex           m_mutex;            ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe
1104    ArchSpec        m_arch;
1105    ModuleList      m_images;           ///< The list of images for this process (shared libraries and anything dynamically loaded).
1106    SectionLoadList m_section_load_list;
1107    BreakpointList  m_breakpoint_list;
1108    BreakpointList  m_internal_breakpoint_list;
1109    lldb::BreakpointSP m_last_created_breakpoint;
1110    WatchpointList  m_watchpoint_list;
1111    lldb::WatchpointSP m_last_created_watchpoint;
1112    // We want to tightly control the process destruction process so
1113    // we can correctly tear down everything that we need to, so the only
1114    // class that knows about the process lifespan is this target class.
1115    lldb::ProcessSP m_process_sp;
1116    bool m_valid;
1117    lldb::SearchFilterSP  m_search_filter_sp;
1118    PathMappingList m_image_search_paths;
1119    std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap;
1120    std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap;
1121    std::auto_ptr<ClangASTImporter> m_ast_importer_ap;
1122    ClangPersistentVariables m_persistent_variables;      ///< These are the persistent variables associated with this process for the expression parser.
1123
1124    SourceManager m_source_manager;
1125
1126    typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
1127    StopHookCollection      m_stop_hooks;
1128    lldb::user_id_t         m_stop_hook_next_id;
1129    bool                    m_suppress_stop_hooks;
1130    bool                    m_suppress_synthetic_value;
1131
1132    static void
1133    ImageSearchPathsChanged (const PathMappingList &path_list,
1134                             void *baton);
1135
1136private:
1137    DISALLOW_COPY_AND_ASSIGN (Target);
1138};
1139
1140} // namespace lldb_private
1141
1142#endif  // liblldb_Target_h_
1143