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