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