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