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