Target.h revision 705a098b207440d81ea4e4ce66ebf1398ec458a3
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/Broadcaster.h"
23#include "lldb/Core/Event.h"
24#include "lldb/Core/ModuleList.h"
25#include "lldb/Core/UserSettingsController.h"
26#include "lldb/Core/SourceManager.h"
27#include "lldb/Expression/ClangPersistentVariables.h"
28#include "lldb/Interpreter/NamedOptionValue.h"
29#include "lldb/Symbol/SymbolContext.h"
30#include "lldb/Target/ABI.h"
31#include "lldb/Target/ExecutionContextScope.h"
32#include "lldb/Target/PathMappingList.h"
33#include "lldb/Target/SectionLoadList.h"
34
35namespace lldb_private {
36
37//----------------------------------------------------------------------
38// TargetInstanceSettings
39//----------------------------------------------------------------------
40class TargetInstanceSettings : public InstanceSettings
41{
42public:
43    static OptionEnumValueElement g_dynamic_value_types[];
44
45    TargetInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
46
47    TargetInstanceSettings (const TargetInstanceSettings &rhs);
48
49    virtual
50    ~TargetInstanceSettings ();
51
52    TargetInstanceSettings&
53    operator= (const TargetInstanceSettings &rhs);
54
55    void
56    UpdateInstanceSettingsVariable (const ConstString &var_name,
57                                    const char *index_value,
58                                    const char *value,
59                                    const ConstString &instance_name,
60                                    const SettingEntry &entry,
61                                    VarSetOperationType op,
62                                    Error &err,
63                                    bool pending);
64
65    bool
66    GetInstanceSettingsValue (const SettingEntry &entry,
67                              const ConstString &var_name,
68                              StringList &value,
69                              Error *err);
70
71    lldb::DynamicValueType
72    GetPreferDynamicValue()
73    {
74        return (lldb::DynamicValueType) g_dynamic_value_types[m_prefer_dynamic_value].value;
75    }
76
77    bool
78    GetSkipPrologue()
79    {
80        return m_skip_prologue;
81    }
82
83    PathMappingList &
84    GetSourcePathMap ()
85    {
86        return m_source_map;
87    }
88
89    uint32_t
90    GetMaximumNumberOfChildrenToDisplay()
91    {
92        return m_max_children_display;
93    }
94    uint32_t
95    GetMaximumSizeOfStringSummary()
96    {
97        return m_max_strlen_length;
98    }
99
100    bool
101    GetBreakpointsConsultPlatformAvoidList ()
102    {
103        return m_breakpoints_use_platform_avoid;
104    }
105
106protected:
107
108    void
109    CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
110                          bool pending);
111
112    const ConstString
113    CreateInstanceName ();
114
115    OptionValueFileSpec m_expr_prefix_file;
116    lldb::DataBufferSP m_expr_prefix_contents_sp;
117    int                m_prefer_dynamic_value;
118    OptionValueBoolean m_skip_prologue;
119    PathMappingList m_source_map;
120    uint32_t m_max_children_display;
121    uint32_t m_max_strlen_length;
122    OptionValueBoolean m_breakpoints_use_platform_avoid;
123
124
125};
126
127//----------------------------------------------------------------------
128// Target
129//----------------------------------------------------------------------
130class Target :
131    public ReferenceCountedBaseVirtual<Target>,
132    public Broadcaster,
133    public ExecutionContextScope,
134    public TargetInstanceSettings
135{
136public:
137    friend class TargetList;
138
139    //------------------------------------------------------------------
140    /// Broadcaster event bits definitions.
141    //------------------------------------------------------------------
142    enum
143    {
144        eBroadcastBitBreakpointChanged  = (1 << 0),
145        eBroadcastBitModulesLoaded      = (1 << 1),
146        eBroadcastBitModulesUnloaded    = (1 << 2)
147    };
148
149    static void
150    SettingsInitialize ();
151
152    static void
153    SettingsTerminate ();
154
155    static lldb::UserSettingsControllerSP &
156    GetSettingsController ();
157
158    static ArchSpec
159    GetDefaultArchitecture ();
160
161    static void
162    SetDefaultArchitecture (const ArchSpec &arch);
163
164    void
165    UpdateInstanceName ();
166
167    lldb::ModuleSP
168    GetSharedModule (const FileSpec& file_spec,
169                     const ArchSpec& arch,
170                     const lldb_private::UUID *uuid = NULL,
171                     const ConstString *object_name = NULL,
172                     off_t object_offset = 0,
173                     Error *error_ptr = NULL);
174private:
175    //------------------------------------------------------------------
176    /// Construct with optional file and arch.
177    ///
178    /// This member is private. Clients must use
179    /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
180    /// so all targets can be tracked from the central target list.
181    ///
182    /// @see TargetList::CreateTarget(const FileSpec*, const ArchSpec*)
183    //------------------------------------------------------------------
184    Target (Debugger &debugger,
185            const ArchSpec &target_arch,
186            const lldb::PlatformSP &platform_sp);
187
188    // Helper function.
189    bool
190    ProcessIsValid ();
191
192public:
193    ~Target();
194
195    Mutex &
196    GetAPIMutex ()
197    {
198        return m_mutex;
199    }
200
201    void
202    DeleteCurrentProcess ();
203
204    //------------------------------------------------------------------
205    /// Dump a description of this object to a Stream.
206    ///
207    /// Dump a description of the contents of this object to the
208    /// supplied stream \a s. The dumped content will be only what has
209    /// been loaded or parsed up to this point at which this function
210    /// is called, so this is a good way to see what has been parsed
211    /// in a target.
212    ///
213    /// @param[in] s
214    ///     The stream to which to dump the object descripton.
215    //------------------------------------------------------------------
216    void
217    Dump (Stream *s, lldb::DescriptionLevel description_level);
218
219    const lldb::ProcessSP &
220    CreateProcess (Listener &listener, const char *plugin_name = NULL);
221
222    const lldb::ProcessSP &
223    GetProcessSP () const;
224
225    lldb::TargetSP
226    GetSP();
227
228    void
229    Destroy();
230
231    //------------------------------------------------------------------
232    // This part handles the breakpoints.
233    //------------------------------------------------------------------
234
235    BreakpointList &
236    GetBreakpointList(bool internal = false);
237
238    const BreakpointList &
239    GetBreakpointList(bool internal = false) const;
240
241    lldb::BreakpointSP
242    GetLastCreatedBreakpoint ()
243    {
244        return m_last_created_breakpoint;
245    }
246
247    lldb::BreakpointSP
248    GetBreakpointByID (lldb::break_id_t break_id);
249
250    // Use this to create a file and line breakpoint to a given module or all module it is NULL
251    lldb::BreakpointSP
252    CreateBreakpoint (const FileSpecList *containingModules,
253                      const FileSpec &file,
254                      uint32_t line_no,
255                      bool check_inlines,
256                      bool internal = false);
257
258    // Use this to create breakpoint that matches regex against the source lines in files given in source_file_list:
259    lldb::BreakpointSP
260    CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
261                      const FileSpecList *source_file_list,
262                      RegularExpression &source_regex,
263                      bool internal = false);
264
265    // Use this to create a breakpoint from a load address
266    lldb::BreakpointSP
267    CreateBreakpoint (lldb::addr_t load_addr,
268                      bool internal = false);
269
270    // Use this to create Address breakpoints:
271    lldb::BreakpointSP
272    CreateBreakpoint (Address &addr,
273                      bool internal = false);
274
275    // Use this to create a function breakpoint by regexp in containingModule/containingSourceFiles, or all modules if it is NULL
276    // When "skip_prologue is set to eLazyBoolCalculate, we use the current target
277    // setting, else we use the values passed in
278    lldb::BreakpointSP
279    CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
280                      const FileSpecList *containingSourceFiles,
281                      RegularExpression &func_regexp,
282                      bool internal = false,
283                      LazyBool skip_prologue = eLazyBoolCalculate);
284
285    // Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL
286    // When "skip_prologue is set to eLazyBoolCalculate, we use the current target
287    // setting, else we use the values passed in
288    lldb::BreakpointSP
289    CreateBreakpoint (const FileSpecList *containingModules,
290                      const FileSpecList *containingSourceFiles,
291                      const char *func_name,
292                      uint32_t func_name_type_mask,
293                      bool internal = false,
294                      LazyBool skip_prologue = eLazyBoolCalculate);
295
296    // Use this to create a general breakpoint:
297    lldb::BreakpointSP
298    CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
299                      lldb::BreakpointResolverSP &resolver_sp,
300                      bool internal = false);
301
302    // Use this to create a watchpoint:
303    lldb::WatchpointSP
304    CreateWatchpoint (lldb::addr_t addr,
305                      size_t size,
306                      uint32_t type);
307
308    lldb::WatchpointSP
309    GetLastCreatedWatchpoint ()
310    {
311        return m_last_created_watchpoint;
312    }
313
314    WatchpointList &
315    GetWatchpointList()
316    {
317        return m_watchpoint_list;
318    }
319
320    void
321    RemoveAllBreakpoints (bool internal_also = false);
322
323    void
324    DisableAllBreakpoints (bool internal_also = false);
325
326    void
327    EnableAllBreakpoints (bool internal_also = false);
328
329    bool
330    DisableBreakpointByID (lldb::break_id_t break_id);
331
332    bool
333    EnableBreakpointByID (lldb::break_id_t break_id);
334
335    bool
336    RemoveBreakpointByID (lldb::break_id_t break_id);
337
338    // The flag 'end_to_end', default to true, signifies that the operation is
339    // performed end to end, for both the debugger and the debuggee.
340
341    bool
342    RemoveAllWatchpoints (bool end_to_end = true);
343
344    bool
345    DisableAllWatchpoints (bool end_to_end = true);
346
347    bool
348    EnableAllWatchpoints (bool end_to_end = true);
349
350    bool
351    IgnoreAllWatchpoints (uint32_t ignore_count);
352
353    bool
354    DisableWatchpointByID (lldb::watch_id_t watch_id);
355
356    bool
357    EnableWatchpointByID (lldb::watch_id_t watch_id);
358
359    bool
360    RemoveWatchpointByID (lldb::watch_id_t watch_id);
361
362    bool
363    IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count);
364
365    void
366    ModulesDidLoad (ModuleList &module_list);
367
368    void
369    ModulesDidUnload (ModuleList &module_list);
370
371
372    //------------------------------------------------------------------
373    /// Get \a load_addr as a callable code load address for this target
374    ///
375    /// Take \a load_addr and potentially add any address bits that are
376    /// needed to make the address callable. For ARM this can set bit
377    /// zero (if it already isn't) if \a load_addr is a thumb function.
378    /// If \a addr_class is set to eAddressClassInvalid, then the address
379    /// adjustment will always happen. If it is set to an address class
380    /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
381    /// returned.
382    //------------------------------------------------------------------
383    lldb::addr_t
384    GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const;
385
386    //------------------------------------------------------------------
387    /// Get \a load_addr as an opcode for this target.
388    ///
389    /// Take \a load_addr and potentially strip any address bits that are
390    /// needed to make the address point to an opcode. For ARM this can
391    /// clear bit zero (if it already isn't) if \a load_addr is a
392    /// thumb function and load_addr is in code.
393    /// If \a addr_class is set to eAddressClassInvalid, then the address
394    /// adjustment will always happen. If it is set to an address class
395    /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
396    /// returned.
397    //------------------------------------------------------------------
398    lldb::addr_t
399    GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class = lldb_private::eAddressClassInvalid) const;
400
401protected:
402    void
403    ModuleAdded (lldb::ModuleSP &module_sp);
404
405    void
406    ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp);
407
408public:
409    //------------------------------------------------------------------
410    /// Gets the module for the main executable.
411    ///
412    /// Each process has a notion of a main executable that is the file
413    /// that will be executed or attached to. Executable files can have
414    /// dependent modules that are discovered from the object files, or
415    /// discovered at runtime as things are dynamically loaded.
416    ///
417    /// @return
418    ///     The shared pointer to the executable module which can
419    ///     contains a NULL Module object if no executable has been
420    ///     set.
421    ///
422    /// @see DynamicLoader
423    /// @see ObjectFile::GetDependentModules (FileSpecList&)
424    /// @see Process::SetExecutableModule(lldb::ModuleSP&)
425    //------------------------------------------------------------------
426    lldb::ModuleSP
427    GetExecutableModule ();
428
429    Module*
430    GetExecutableModulePointer ();
431
432    //------------------------------------------------------------------
433    /// Set the main executable module.
434    ///
435    /// Each process has a notion of a main executable that is the file
436    /// that will be executed or attached to. Executable files can have
437    /// dependent modules that are discovered from the object files, or
438    /// discovered at runtime as things are dynamically loaded.
439    ///
440    /// Setting the executable causes any of the current dependant
441    /// image information to be cleared and replaced with the static
442    /// dependent image information found by calling
443    /// ObjectFile::GetDependentModules (FileSpecList&) on the main
444    /// executable and any modules on which it depends. Calling
445    /// Process::GetImages() will return the newly found images that
446    /// were obtained from all of the object files.
447    ///
448    /// @param[in] module_sp
449    ///     A shared pointer reference to the module that will become
450    ///     the main executable for this process.
451    ///
452    /// @param[in] get_dependent_files
453    ///     If \b true then ask the object files to track down any
454    ///     known dependent files.
455    ///
456    /// @see ObjectFile::GetDependentModules (FileSpecList&)
457    /// @see Process::GetImages()
458    //------------------------------------------------------------------
459    void
460    SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
461
462    //------------------------------------------------------------------
463    /// Get accessor for the images for this process.
464    ///
465    /// Each process has a notion of a main executable that is the file
466    /// that will be executed or attached to. Executable files can have
467    /// dependent modules that are discovered from the object files, or
468    /// discovered at runtime as things are dynamically loaded. After
469    /// a main executable has been set, the images will contain a list
470    /// of all the files that the executable depends upon as far as the
471    /// object files know. These images will usually contain valid file
472    /// virtual addresses only. When the process is launched or attached
473    /// to, the DynamicLoader plug-in will discover where these images
474    /// were loaded in memory and will resolve the load virtual
475    /// addresses is each image, and also in images that are loaded by
476    /// code.
477    ///
478    /// @return
479    ///     A list of Module objects in a module list.
480    //------------------------------------------------------------------
481    ModuleList&
482    GetImages ()
483    {
484        return m_images;
485    }
486
487    const ModuleList&
488    GetImages () const
489    {
490        return m_images;
491    }
492
493
494    //------------------------------------------------------------------
495    /// Return whether this FileSpec corresponds to a module that should be considered for general searches.
496    ///
497    /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
498    /// and any module that returns \b true will not be searched.  Note the
499    /// SearchFilterForNonModuleSpecificSearches is the search filter that
500    /// gets used in the CreateBreakpoint calls when no modules is provided.
501    ///
502    /// The target call at present just consults the Platform's call of the
503    /// same name.
504    ///
505    /// @param[in] module_sp
506    ///     A shared pointer reference to the module that checked.
507    ///
508    /// @return \b true if the module should be excluded, \b false otherwise.
509    //------------------------------------------------------------------
510    bool
511    ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec);
512
513    //------------------------------------------------------------------
514    /// Return whether this module should be considered for general searches.
515    ///
516    /// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
517    /// and any module that returns \b true will not be searched.  Note the
518    /// SearchFilterForNonModuleSpecificSearches is the search filter that
519    /// gets used in the CreateBreakpoint calls when no modules is provided.
520    ///
521    /// The target call at present just consults the Platform's call of the
522    /// same name.
523    ///
524    /// FIXME: When we get time we should add a way for the user to set modules that they
525    /// don't want searched, in addition to or instead of the platform ones.
526    ///
527    /// @param[in] module_sp
528    ///     A shared pointer reference to the module that checked.
529    ///
530    /// @return \b true if the module should be excluded, \b false otherwise.
531    //------------------------------------------------------------------
532    bool
533    ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp);
534
535    ArchSpec &
536    GetArchitecture ()
537    {
538        return m_arch;
539    }
540
541    const ArchSpec &
542    GetArchitecture () const
543    {
544        return m_arch;
545    }
546
547    //------------------------------------------------------------------
548    /// Set the architecture for this target.
549    ///
550    /// If the current target has no Images read in, then this just sets the architecture, which will
551    /// be used to select the architecture of the ExecutableModule when that is set.
552    /// If the current target has an ExecutableModule, then calling SetArchitecture with a different
553    /// architecture from the currently selected one will reset the ExecutableModule to that slice
554    /// of the file backing the ExecutableModule.  If the file backing the ExecutableModule does not
555    /// contain a fork of this architecture, then this code will return false, and the architecture
556    /// won't be changed.
557    /// If the input arch_spec is the same as the already set architecture, this is a no-op.
558    ///
559    /// @param[in] arch_spec
560    ///     The new architecture.
561    ///
562    /// @return
563    ///     \b true if the architecture was successfully set, \bfalse otherwise.
564    //------------------------------------------------------------------
565    bool
566    SetArchitecture (const ArchSpec &arch_spec);
567
568    Debugger &
569    GetDebugger ()
570    {
571        return m_debugger;
572    }
573
574    size_t
575    ReadMemoryFromFileCache (const Address& addr,
576                             void *dst,
577                             size_t dst_len,
578                             Error &error);
579
580    // Reading memory through the target allows us to skip going to the process
581    // for reading memory if possible and it allows us to try and read from
582    // any constant sections in our object files on disk. If you always want
583    // live program memory, read straight from the process. If you possibly
584    // want to read from const sections in object files, read from the target.
585    // This version of ReadMemory will try and read memory from the process
586    // if the process is alive. The order is:
587    // 1 - if (prefer_file_cache == true) then read from object file cache
588    // 2 - if there is a valid process, try and read from its memory
589    // 3 - if (prefer_file_cache == false) then read from object file cache
590    size_t
591    ReadMemory (const Address& addr,
592                bool prefer_file_cache,
593                void *dst,
594                size_t dst_len,
595                Error &error,
596                lldb::addr_t *load_addr_ptr = NULL);
597
598    size_t
599    ReadScalarIntegerFromMemory (const Address& addr,
600                                 bool prefer_file_cache,
601                                 uint32_t byte_size,
602                                 bool is_signed,
603                                 Scalar &scalar,
604                                 Error &error);
605
606    uint64_t
607    ReadUnsignedIntegerFromMemory (const Address& addr,
608                                   bool prefer_file_cache,
609                                   size_t integer_byte_size,
610                                   uint64_t fail_value,
611                                   Error &error);
612
613    bool
614    ReadPointerFromMemory (const Address& addr,
615                           bool prefer_file_cache,
616                           Error &error,
617                           Address &pointer_addr);
618
619    SectionLoadList&
620    GetSectionLoadList()
621    {
622        return m_section_load_list;
623    }
624
625    const SectionLoadList&
626    GetSectionLoadList() const
627    {
628        return m_section_load_list;
629    }
630
631
632    //------------------------------------------------------------------
633    /// Load a module in this target by at the section file addresses
634    /// with an optional constant slide applied to each section.
635    ///
636    /// This function will load all top level sections at their file
637    /// addresses and apply an optional constant slide amount to each
638    /// section. This can be used to easily load a module at the same
639    /// addresses that are contained in the object file (trust that
640    /// the addresses in an object file are the correct load addresses).
641    ///
642    /// @param[in] module
643    ///     The module to load.
644    ///
645    /// @param[in] slide
646    ///     A constant slide to add to each file address as each section
647    ///     is being loaded.
648    ///
649    /// @return
650    ///     \b true if loading the module at the specified address
651    ///     causes a section to be loaded when it previously wasn't, or
652    ///     if a section changes load address. Returns \b false if
653    ///     the sections were all already loaded at these addresses.
654    //------------------------------------------------------------------
655    bool
656    LoadModuleWithSlide (Module *module, lldb::addr_t slide);
657
658    static Target *
659    GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr,
660                           const SymbolContext *sc_ptr);
661
662    //------------------------------------------------------------------
663    // lldb::ExecutionContextScope pure virtual functions
664    //------------------------------------------------------------------
665    virtual Target *
666    CalculateTarget ();
667
668    virtual Process *
669    CalculateProcess ();
670
671    virtual Thread *
672    CalculateThread ();
673
674    virtual StackFrame *
675    CalculateStackFrame ();
676
677    virtual void
678    CalculateExecutionContext (ExecutionContext &exe_ctx);
679
680    PathMappingList &
681    GetImageSearchPathList ();
682
683    ClangASTContext *
684    GetScratchClangASTContext();
685
686    const char *
687    GetExpressionPrefixContentsAsCString ();
688
689    // Since expressions results can persist beyond the lifetime of a process,
690    // and the const expression results are available after a process is gone,
691    // we provide a way for expressions to be evaluated from the Target itself.
692    // If an expression is going to be run, then it should have a frame filled
693    // in in th execution context.
694    ExecutionResults
695    EvaluateExpression (const char *expression,
696                        StackFrame *frame,
697                        lldb_private::ExecutionPolicy execution_policy,
698                        bool unwind_on_error,
699                        bool keep_in_memory,
700                        lldb::DynamicValueType use_dynamic,
701                        lldb::ValueObjectSP &result_valobj_sp);
702
703    ClangPersistentVariables &
704    GetPersistentVariables()
705    {
706        return m_persistent_variables;
707    }
708
709    //------------------------------------------------------------------
710    // Target Stop Hooks
711    //------------------------------------------------------------------
712    class StopHook : public UserID
713    {
714    public:
715        ~StopHook ();
716
717        StopHook (const StopHook &rhs);
718
719        StringList *
720        GetCommandPointer ()
721        {
722            return &m_commands;
723        }
724
725        const StringList &
726        GetCommands()
727        {
728            return m_commands;
729        }
730
731        lldb::TargetSP &
732        GetTarget()
733        {
734            return m_target_sp;
735        }
736
737        void
738        SetCommands (StringList &in_commands)
739        {
740            m_commands = in_commands;
741        }
742
743        // Set the specifier.  The stop hook will own the specifier, and is responsible for deleting it when we're done.
744        void
745        SetSpecifier (SymbolContextSpecifier *specifier)
746        {
747            m_specifier_sp.reset (specifier);
748        }
749
750        SymbolContextSpecifier *
751        GetSpecifier ()
752        {
753            return m_specifier_sp.get();
754        }
755
756        // Set the Thread Specifier.  The stop hook will own the thread specifier, and is responsible for deleting it when we're done.
757        void
758        SetThreadSpecifier (ThreadSpec *specifier);
759
760        ThreadSpec *
761        GetThreadSpecifier()
762        {
763            return m_thread_spec_ap.get();
764        }
765
766        bool
767        IsActive()
768        {
769            return m_active;
770        }
771
772        void
773        SetIsActive (bool is_active)
774        {
775            m_active = is_active;
776        }
777
778        void
779        GetDescription (Stream *s, lldb::DescriptionLevel level) const;
780
781    private:
782        lldb::TargetSP m_target_sp;
783        StringList   m_commands;
784        lldb::SymbolContextSpecifierSP m_specifier_sp;
785        std::auto_ptr<ThreadSpec> m_thread_spec_ap;
786        bool m_active;
787
788        // Use AddStopHook to make a new empty stop hook.  The GetCommandPointer and fill it with commands,
789        // and SetSpecifier to set the specifier shared pointer (can be null, that will match anything.)
790        StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid);
791        friend class Target;
792    };
793    typedef lldb::SharedPtr<StopHook>::Type StopHookSP;
794
795    // Add an empty stop hook to the Target's stop hook list, and returns a shared pointer to it in new_hook.
796    // Returns the id of the new hook.
797    lldb::user_id_t
798    AddStopHook (StopHookSP &new_hook);
799
800    void
801    RunStopHooks ();
802
803    size_t
804    GetStopHookSize();
805
806    bool
807    SetSuppresStopHooks (bool suppress)
808    {
809        bool old_value = m_suppress_stop_hooks;
810        m_suppress_stop_hooks = suppress;
811        return old_value;
812    }
813
814    bool
815    GetSuppressStopHooks ()
816    {
817        return m_suppress_stop_hooks;
818    }
819
820//    StopHookSP &
821//    GetStopHookByIndex (size_t index);
822//
823    bool
824    RemoveStopHookByID (lldb::user_id_t uid);
825
826    void
827    RemoveAllStopHooks ();
828
829    StopHookSP
830    GetStopHookByID (lldb::user_id_t uid);
831
832    bool
833    SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state);
834
835    void
836    SetAllStopHooksActiveState (bool active_state);
837
838    size_t GetNumStopHooks () const
839    {
840        return m_stop_hooks.size();
841    }
842
843    StopHookSP
844    GetStopHookAtIndex (size_t index)
845    {
846        if (index >= GetNumStopHooks())
847            return StopHookSP();
848        StopHookCollection::iterator pos = m_stop_hooks.begin();
849
850        while (index > 0)
851        {
852            pos++;
853            index--;
854        }
855        return (*pos).second;
856    }
857
858    lldb::PlatformSP
859    GetPlatform ()
860    {
861        return m_platform_sp;
862    }
863
864    SourceManager &
865    GetSourceManager ()
866    {
867        return m_source_manager;
868    }
869
870    //------------------------------------------------------------------
871    // Target::SettingsController
872    //------------------------------------------------------------------
873    class SettingsController : public UserSettingsController
874    {
875    public:
876        SettingsController ();
877
878        virtual
879        ~SettingsController ();
880
881        bool
882        SetGlobalVariable (const ConstString &var_name,
883                           const char *index_value,
884                           const char *value,
885                           const SettingEntry &entry,
886                           const VarSetOperationType op,
887                           Error&err);
888
889        bool
890        GetGlobalVariable (const ConstString &var_name,
891                           StringList &value,
892                           Error &err);
893
894        static SettingEntry global_settings_table[];
895        static SettingEntry instance_settings_table[];
896
897        ArchSpec &
898        GetArchitecture ()
899        {
900            return m_default_architecture;
901        }
902    protected:
903
904        lldb::InstanceSettingsSP
905        CreateInstanceSettings (const char *instance_name);
906
907    private:
908
909        // Class-wide settings.
910        ArchSpec m_default_architecture;
911
912        DISALLOW_COPY_AND_ASSIGN (SettingsController);
913    };
914
915
916protected:
917    //------------------------------------------------------------------
918    // Member variables.
919    //------------------------------------------------------------------
920    Debugger &      m_debugger;
921    lldb::PlatformSP m_platform_sp;     ///< The platform for this target.
922    Mutex           m_mutex;            ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe
923    ArchSpec        m_arch;
924    ModuleList      m_images;           ///< The list of images for this process (shared libraries and anything dynamically loaded).
925    SectionLoadList m_section_load_list;
926    BreakpointList  m_breakpoint_list;
927    BreakpointList  m_internal_breakpoint_list;
928    lldb::BreakpointSP m_last_created_breakpoint;
929    WatchpointList  m_watchpoint_list;
930    lldb::WatchpointSP m_last_created_watchpoint;
931    // We want to tightly control the process destruction process so
932    // we can correctly tear down everything that we need to, so the only
933    // class that knows about the process lifespan is this target class.
934    lldb::ProcessSP m_process_sp;
935    lldb::SearchFilterSP  m_search_filter_sp;
936    PathMappingList m_image_search_paths;
937    std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap;
938    ClangPersistentVariables m_persistent_variables;      ///< These are the persistent variables associated with this process for the expression parser.
939
940    SourceManager m_source_manager;
941
942    typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
943    StopHookCollection      m_stop_hooks;
944    lldb::user_id_t         m_stop_hook_next_id;
945    bool                    m_suppress_stop_hooks;
946
947    //------------------------------------------------------------------
948    // Methods.
949    //------------------------------------------------------------------
950    lldb::SearchFilterSP
951    GetSearchFilterForModule (const FileSpec *containingModule);
952
953    lldb::SearchFilterSP
954    GetSearchFilterForModuleList (const FileSpecList *containingModuleList);
955
956    lldb::SearchFilterSP
957    GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles);
958
959
960    static void
961    ImageSearchPathsChanged (const PathMappingList &path_list,
962                             void *baton);
963
964private:
965    DISALLOW_COPY_AND_ASSIGN (Target);
966};
967
968} // namespace lldb_private
969
970#endif  // liblldb_Target_h_
971