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