]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/Breakpoint.h
MFV r330591: 8984 fix for 6764 breaks ACL inheritance
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Breakpoint / Breakpoint.h
1 //===-- Breakpoint.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_Breakpoint_h_
11 #define liblldb_Breakpoint_h_
12
13 // C Includes
14 // C++ Includes
15 #include <memory>
16 #include <string>
17 #include <unordered_set>
18 #include <vector>
19
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/Breakpoint/BreakpointID.h"
23 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
24 #include "lldb/Breakpoint/BreakpointLocationList.h"
25 #include "lldb/Breakpoint/BreakpointName.h"
26 #include "lldb/Breakpoint/BreakpointOptions.h"
27 #include "lldb/Breakpoint/Stoppoint.h"
28 #include "lldb/Core/Event.h"
29 #include "lldb/Core/SearchFilter.h"
30 #include "lldb/Utility/StringList.h"
31 #include "lldb/Utility/StructuredData.h"
32
33 namespace lldb_private {
34
35 //----------------------------------------------------------------------
36 /// @class Breakpoint Breakpoint.h "lldb/Breakpoint/Breakpoint.h"
37 /// @brief Class that manages logical breakpoint setting.
38 //----------------------------------------------------------------------
39
40 //----------------------------------------------------------------------
41 /// General Outline:
42 /// A breakpoint has four main parts, a filter, a resolver, the list of
43 /// breakpoint
44 /// locations that have been determined for the filter/resolver pair, and
45 /// finally
46 /// a set of options for the breakpoint.
47 ///
48 /// \b Filter:
49 /// This is an object derived from SearchFilter.  It manages the search
50 /// for breakpoint location matches through the symbols in the module list of
51 /// the target
52 /// that owns it.  It also filters out locations based on whatever logic it
53 /// wants.
54 ///
55 /// \b Resolver:
56 /// This is an object derived from BreakpointResolver.  It provides a
57 /// callback to the filter that will find breakpoint locations.  How it does
58 /// this is
59 /// determined by what kind of resolver it is.
60 ///
61 /// The Breakpoint class also provides constructors for the common breakpoint
62 /// cases
63 /// which make the appropriate filter and resolver for you.
64 ///
65 /// \b Location List:
66 /// This stores the breakpoint locations that have been determined
67 /// to date.  For a given breakpoint, there will be only one location with a
68 /// given
69 /// address.  Adding a location at an already taken address will just return the
70 /// location
71 /// already at that address.  Locations can be looked up by ID, or by address.
72 ///
73 /// \b Options:
74 /// This includes:
75 ///    \b Enabled/Disabled
76 ///    \b Ignore Count
77 ///    \b Callback
78 ///    \b Condition
79 /// Note, these options can be set on the breakpoint, and they can also be set
80 /// on the
81 /// individual locations.  The options set on the breakpoint take precedence
82 /// over the
83 /// options set on the individual location.
84 /// So for instance disabling the breakpoint will cause NONE of the locations to
85 /// get hit.
86 /// But if the breakpoint is enabled, then the location's enabled state will be
87 /// checked
88 /// to determine whether to insert that breakpoint location.
89 /// Similarly, if the breakpoint condition says "stop", we won't check the
90 /// location's condition.
91 /// But if the breakpoint condition says "continue", then we will check the
92 /// location for whether
93 /// to actually stop or not.
94 /// One subtle point worth observing here is that you don't actually stop at a
95 /// Breakpoint, you
96 /// always stop at one of its locations.  So the "should stop" tests are done by
97 /// the location,
98 /// not by the breakpoint.
99 //----------------------------------------------------------------------
100 class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
101                    public Stoppoint {
102 public:
103   static const ConstString &GetEventIdentifier();
104
105   //------------------------------------------------------------------
106   /// An enum specifying the match style for breakpoint settings.  At
107   /// present only used for function name style breakpoints.
108   //------------------------------------------------------------------
109   typedef enum { Exact, Regexp, Glob } MatchType;
110
111 private:
112   enum class OptionNames : uint32_t { Names = 0, Hardware, LastOptionName };
113
114   static const char
115       *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
116
117   static const char *GetKey(OptionNames enum_value) {
118     return g_option_names[static_cast<uint32_t>(enum_value)];
119   }
120
121 public:
122   class BreakpointEventData : public EventData {
123   public:
124     BreakpointEventData(lldb::BreakpointEventType sub_type,
125                         const lldb::BreakpointSP &new_breakpoint_sp);
126
127     ~BreakpointEventData() override;
128
129     static const ConstString &GetFlavorString();
130
131     const ConstString &GetFlavor() const override;
132
133     lldb::BreakpointEventType GetBreakpointEventType() const;
134
135     lldb::BreakpointSP &GetBreakpoint();
136
137     BreakpointLocationCollection &GetBreakpointLocationCollection() {
138       return m_locations;
139     }
140
141     void Dump(Stream *s) const override;
142
143     static lldb::BreakpointEventType
144     GetBreakpointEventTypeFromEvent(const lldb::EventSP &event_sp);
145
146     static lldb::BreakpointSP
147     GetBreakpointFromEvent(const lldb::EventSP &event_sp);
148
149     static lldb::BreakpointLocationSP
150     GetBreakpointLocationAtIndexFromEvent(const lldb::EventSP &event_sp,
151                                           uint32_t loc_idx);
152
153     static size_t
154     GetNumBreakpointLocationsFromEvent(const lldb::EventSP &event_sp);
155
156     static const BreakpointEventData *
157     GetEventDataFromEvent(const Event *event_sp);
158
159   private:
160     lldb::BreakpointEventType m_breakpoint_event;
161     lldb::BreakpointSP m_new_breakpoint_sp;
162     BreakpointLocationCollection m_locations;
163
164     DISALLOW_COPY_AND_ASSIGN(BreakpointEventData);
165   };
166
167   class BreakpointPrecondition {
168   public:
169     virtual ~BreakpointPrecondition() = default;
170
171     virtual bool EvaluatePrecondition(StoppointCallbackContext &context);
172
173     virtual Status ConfigurePrecondition(Args &options);
174
175     virtual void GetDescription(Stream &stream, lldb::DescriptionLevel level);
176   };
177
178   typedef std::shared_ptr<BreakpointPrecondition> BreakpointPreconditionSP;
179
180   // Saving & restoring breakpoints:
181   static lldb::BreakpointSP CreateFromStructuredData(
182       Target &target, StructuredData::ObjectSP &data_object_sp, Status &error);
183
184   static bool
185   SerializedBreakpointMatchesNames(StructuredData::ObjectSP &bkpt_object_sp,
186                                    std::vector<std::string> &names);
187
188   virtual StructuredData::ObjectSP SerializeToStructuredData();
189
190   static const char *GetSerializationKey() { return "Breakpoint"; }
191   //------------------------------------------------------------------
192   /// Destructor.
193   ///
194   /// The destructor is not virtual since there should be no reason to subclass
195   /// breakpoints.  The varieties of breakpoints are specified instead by
196   /// providing different resolvers & filters.
197   //------------------------------------------------------------------
198   ~Breakpoint() override;
199
200   //------------------------------------------------------------------
201   // Methods
202   //------------------------------------------------------------------
203
204   //------------------------------------------------------------------
205   /// Tell whether this breakpoint is an "internal" breakpoint.
206   /// @return
207   ///     Returns \b true if this is an internal breakpoint, \b false otherwise.
208   //------------------------------------------------------------------
209   bool IsInternal() const;
210
211   //------------------------------------------------------------------
212   /// Standard "Dump" method.  At present it does nothing.
213   //------------------------------------------------------------------
214   void Dump(Stream *s) override;
215
216   //------------------------------------------------------------------
217   // The next set of methods provide ways to tell the breakpoint to update
218   // it's location list - usually done when modules appear or disappear.
219   //------------------------------------------------------------------
220
221   //------------------------------------------------------------------
222   /// Tell this breakpoint to clear all its breakpoint sites.  Done
223   /// when the process holding the breakpoint sites is destroyed.
224   //------------------------------------------------------------------
225   void ClearAllBreakpointSites();
226
227   //------------------------------------------------------------------
228   /// Tell this breakpoint to scan it's target's module list and resolve any
229   /// new locations that match the breakpoint's specifications.
230   //------------------------------------------------------------------
231   void ResolveBreakpoint();
232
233   //------------------------------------------------------------------
234   /// Tell this breakpoint to scan a given module list and resolve any
235   /// new locations that match the breakpoint's specifications.
236   ///
237   /// @param[in] module_list
238   ///    The list of modules to look in for new locations.
239   ///
240   /// @param[in]  send_event
241   ///     If \b true, send a breakpoint location added event for non-internal
242   ///     breakpoints.
243   //------------------------------------------------------------------
244   void ResolveBreakpointInModules(ModuleList &module_list,
245                                   bool send_event = true);
246
247   //------------------------------------------------------------------
248   /// Tell this breakpoint to scan a given module list and resolve any
249   /// new locations that match the breakpoint's specifications.
250   ///
251   /// @param[in] changed_modules
252   ///    The list of modules to look in for new locations.
253   ///
254   /// @param[in]  new_locations
255   ///     Fills new_locations with the new locations that were made.
256   //------------------------------------------------------------------
257   void ResolveBreakpointInModules(ModuleList &module_list,
258                                   BreakpointLocationCollection &new_locations);
259
260   //------------------------------------------------------------------
261   /// Like ResolveBreakpointInModules, but allows for "unload" events, in
262   /// which case we will remove any locations that are in modules that got
263   /// unloaded.
264   ///
265   /// @param[in] changedModules
266   ///    The list of modules to look in for new locations.
267   /// @param[in] load_event
268   ///    If \b true then the modules were loaded, if \b false, unloaded.
269   /// @param[in] delete_locations
270   ///    If \b true then the modules were unloaded delete any locations in the
271   ///    changed modules.
272   //------------------------------------------------------------------
273   void ModulesChanged(ModuleList &changed_modules, bool load_event,
274                       bool delete_locations = false);
275
276   //------------------------------------------------------------------
277   /// Tells the breakpoint the old module \a old_module_sp has been
278   /// replaced by new_module_sp (usually because the underlying file has been
279   /// rebuilt, and the old version is gone.)
280   ///
281   /// @param[in] old_module_sp
282   ///    The old module that is going away.
283   /// @param[in] new_module_sp
284   ///    The new module that is replacing it.
285   //------------------------------------------------------------------
286   void ModuleReplaced(lldb::ModuleSP old_module_sp,
287                       lldb::ModuleSP new_module_sp);
288
289   //------------------------------------------------------------------
290   // The next set of methods provide access to the breakpoint locations
291   // for this breakpoint.
292   //------------------------------------------------------------------
293
294   //------------------------------------------------------------------
295   /// Add a location to the breakpoint's location list.  This is only meant
296   /// to be called by the breakpoint's resolver.  FIXME: how do I ensure that?
297   ///
298   /// @param[in] addr
299   ///    The Address specifying the new location.
300   /// @param[out] new_location
301   ///    Set to \b true if a new location was created, to \b false if there
302   ///    already was a location at this Address.
303   /// @return
304   ///    Returns a pointer to the new location.
305   //------------------------------------------------------------------
306   lldb::BreakpointLocationSP AddLocation(const Address &addr,
307                                          bool *new_location = nullptr);
308
309   //------------------------------------------------------------------
310   /// Find a breakpoint location by Address.
311   ///
312   /// @param[in] addr
313   ///    The Address specifying the location.
314   /// @return
315   ///    Returns a shared pointer to the location at \a addr.  The pointer
316   ///    in the shared pointer will be nullptr if there is no location at that
317   ///    address.
318   //------------------------------------------------------------------
319   lldb::BreakpointLocationSP FindLocationByAddress(const Address &addr);
320
321   //------------------------------------------------------------------
322   /// Find a breakpoint location ID by Address.
323   ///
324   /// @param[in] addr
325   ///    The Address specifying the location.
326   /// @return
327   ///    Returns the UID of the location at \a addr, or \b LLDB_INVALID_ID if
328   ///    there is no breakpoint location at that address.
329   //------------------------------------------------------------------
330   lldb::break_id_t FindLocationIDByAddress(const Address &addr);
331
332   //------------------------------------------------------------------
333   /// Find a breakpoint location for a given breakpoint location ID.
334   ///
335   /// @param[in] bp_loc_id
336   ///    The ID specifying the location.
337   /// @return
338   ///    Returns a shared pointer to the location with ID \a bp_loc_id.  The
339   ///    pointer
340   ///    in the shared pointer will be nullptr if there is no location with that
341   ///    ID.
342   //------------------------------------------------------------------
343   lldb::BreakpointLocationSP FindLocationByID(lldb::break_id_t bp_loc_id);
344
345   //------------------------------------------------------------------
346   /// Get breakpoint locations by index.
347   ///
348   /// @param[in] index
349   ///    The location index.
350   ///
351   /// @return
352   ///     Returns a shared pointer to the location with index \a
353   ///     index. The shared pointer might contain nullptr if \a index is
354   ///     greater than then number of actual locations.
355   //------------------------------------------------------------------
356   lldb::BreakpointLocationSP GetLocationAtIndex(size_t index);
357
358   //------------------------------------------------------------------
359   /// Removes all invalid breakpoint locations.
360   ///
361   /// Removes all breakpoint locations with architectures that aren't
362   /// compatible with \a arch. Also remove any breakpoint locations
363   /// with whose locations have address where the section has been
364   /// deleted (module and object files no longer exist).
365   ///
366   /// This is typically used after the process calls exec, or anytime
367   /// the architecture of the target changes.
368   ///
369   /// @param[in] arch
370   ///     If valid, check the module in each breakpoint to make sure
371   ///     they are compatible, otherwise, ignore architecture.
372   //------------------------------------------------------------------
373   void RemoveInvalidLocations(const ArchSpec &arch);
374
375   //------------------------------------------------------------------
376   // The next section deals with various breakpoint options.
377   //------------------------------------------------------------------
378
379   //------------------------------------------------------------------
380   /// If \a enable is \b true, enable the breakpoint, if \b false disable it.
381   //------------------------------------------------------------------
382   void SetEnabled(bool enable) override;
383
384   //------------------------------------------------------------------
385   /// Check the Enable/Disable state.
386   /// @return
387   ///     \b true if the breakpoint is enabled, \b false if disabled.
388   //------------------------------------------------------------------
389   bool IsEnabled() override;
390
391   //------------------------------------------------------------------
392   /// Set the breakpoint to ignore the next \a count breakpoint hits.
393   /// @param[in] count
394   ///    The number of breakpoint hits to ignore.
395   //------------------------------------------------------------------
396   void SetIgnoreCount(uint32_t count);
397
398   //------------------------------------------------------------------
399   /// Return the current ignore count/
400   /// @return
401   ///     The number of breakpoint hits to be ignored.
402   //------------------------------------------------------------------
403   uint32_t GetIgnoreCount() const;
404
405   //------------------------------------------------------------------
406   /// Return the current hit count for all locations.
407   /// @return
408   ///     The current hit count for all locations.
409   //------------------------------------------------------------------
410   uint32_t GetHitCount() const;
411
412   //------------------------------------------------------------------
413   /// If \a one_shot is \b true, breakpoint will be deleted on first hit.
414   //------------------------------------------------------------------
415   void SetOneShot(bool one_shot);
416
417   //------------------------------------------------------------------
418   /// Check the OneShot state.
419   /// @return
420   ///     \b true if the breakpoint is one shot, \b false otherwise.
421   //------------------------------------------------------------------
422   bool IsOneShot() const;
423
424   //------------------------------------------------------------------
425   /// If \a auto_continue is \b true, breakpoint will auto-continue when on hit.
426   //------------------------------------------------------------------
427   void SetAutoContinue(bool auto_continue);
428
429   //------------------------------------------------------------------
430   /// Check the AutoContinue state.
431   /// @return
432   ///     \b true if the breakpoint is set to auto-continue, \b false otherwise.
433   //------------------------------------------------------------------
434   bool IsAutoContinue() const;
435
436   //------------------------------------------------------------------
437   /// Set the valid thread to be checked when the breakpoint is hit.
438   /// @param[in] thread_id
439   ///    If this thread hits the breakpoint, we stop, otherwise not.
440   //------------------------------------------------------------------
441   void SetThreadID(lldb::tid_t thread_id);
442
443   //------------------------------------------------------------------
444   /// Return the current stop thread value.
445   /// @return
446   ///     The thread id for which the breakpoint hit will stop,
447   ///     LLDB_INVALID_THREAD_ID for all threads.
448   //------------------------------------------------------------------
449   lldb::tid_t GetThreadID() const;
450
451   void SetThreadIndex(uint32_t index);
452
453   uint32_t GetThreadIndex() const;
454
455   void SetThreadName(const char *thread_name);
456
457   const char *GetThreadName() const;
458
459   void SetQueueName(const char *queue_name);
460
461   const char *GetQueueName() const;
462
463   //------------------------------------------------------------------
464   /// Set the callback action invoked when the breakpoint is hit.
465   ///
466   /// @param[in] callback
467   ///    The method that will get called when the breakpoint is hit.
468   /// @param[in] baton
469   ///    A void * pointer that will get passed back to the callback function.
470   /// @param[in] is_synchronous
471   ///    If \b true the callback will be run on the private event thread
472   ///    before the stop event gets reported.  If false, the callback will get
473   ///    handled on the public event thread after the stop has been posted.
474   ///
475   /// @return
476   ///    \b true if the process should stop when you hit the breakpoint.
477   ///    \b false if it should continue.
478   //------------------------------------------------------------------
479   void SetCallback(BreakpointHitCallback callback, void *baton,
480                    bool is_synchronous = false);
481
482   void SetCallback(BreakpointHitCallback callback,
483                    const lldb::BatonSP &callback_baton_sp,
484                    bool is_synchronous = false);
485
486   void ClearCallback();
487
488   //------------------------------------------------------------------
489   /// Set the breakpoint's condition.
490   ///
491   /// @param[in] condition
492   ///    The condition expression to evaluate when the breakpoint is hit.
493   ///    Pass in nullptr to clear the condition.
494   //------------------------------------------------------------------
495   void SetCondition(const char *condition);
496
497   //------------------------------------------------------------------
498   /// Return a pointer to the text of the condition expression.
499   ///
500   /// @return
501   ///    A pointer to the condition expression text, or nullptr if no
502   //     condition has been set.
503   //------------------------------------------------------------------
504   const char *GetConditionText() const;
505
506   //------------------------------------------------------------------
507   // The next section are various utility functions.
508   //------------------------------------------------------------------
509
510   //------------------------------------------------------------------
511   /// Return the number of breakpoint locations that have resolved to
512   /// actual breakpoint sites.
513   ///
514   /// @return
515   ///     The number locations resolved breakpoint sites.
516   //------------------------------------------------------------------
517   size_t GetNumResolvedLocations() const;
518
519   //------------------------------------------------------------------
520   /// Return the number of breakpoint locations.
521   ///
522   /// @return
523   ///     The number breakpoint locations.
524   //------------------------------------------------------------------
525   size_t GetNumLocations() const;
526
527   //------------------------------------------------------------------
528   /// Put a description of this breakpoint into the stream \a s.
529   ///
530   /// @param[in] s
531   ///     Stream into which to dump the description.
532   ///
533   /// @param[in] level
534   ///     The description level that indicates the detail level to
535   ///     provide.
536   ///
537   /// @see lldb::DescriptionLevel
538   //------------------------------------------------------------------
539   void GetDescription(Stream *s, lldb::DescriptionLevel level,
540                       bool show_locations = false);
541
542   //------------------------------------------------------------------
543   /// Set the "kind" description for a breakpoint.  If the breakpoint is hit
544   /// the stop info will show this "kind" description instead of the breakpoint
545   /// number.  Mostly useful for internal breakpoints, where the breakpoint
546   /// number
547   /// doesn't have meaning to the user.
548   ///
549   /// @param[in] kind
550   ///     New "kind" description.
551   //------------------------------------------------------------------
552   void SetBreakpointKind(const char *kind) { m_kind_description.assign(kind); }
553
554   //------------------------------------------------------------------
555   /// Return the "kind" description for a breakpoint.
556   ///
557   /// @return
558   ///     The breakpoint kind, or nullptr if none is set.
559   //------------------------------------------------------------------
560   const char *GetBreakpointKind() const { return m_kind_description.c_str(); }
561
562   //------------------------------------------------------------------
563   /// Accessor for the breakpoint Target.
564   /// @return
565   ///     This breakpoint's Target.
566   //------------------------------------------------------------------
567   Target &GetTarget() { return m_target; }
568
569   const Target &GetTarget() const { return m_target; }
570
571   const lldb::TargetSP GetTargetSP();
572
573   void GetResolverDescription(Stream *s);
574
575   //------------------------------------------------------------------
576   /// Find breakpoint locations which match the (filename, line_number)
577   /// description.
578   /// The breakpoint location collection is to be filled with the matching
579   /// locations.
580   /// It should be initialized with 0 size by the API client.
581   ///
582   /// @return
583   ///     True if there is a match
584   ///
585   ///     The locations which match the filename and line_number in loc_coll.
586   ///     If its
587   ///     size is 0 and true is returned, it means the breakpoint fully matches
588   ///     the
589   ///     description.
590   //------------------------------------------------------------------
591   bool GetMatchingFileLine(const ConstString &filename, uint32_t line_number,
592                            BreakpointLocationCollection &loc_coll);
593
594   void GetFilterDescription(Stream *s);
595
596   //------------------------------------------------------------------
597   /// Returns the BreakpointOptions structure set at the breakpoint level.
598   ///
599   /// Meant to be used by the BreakpointLocation class.
600   ///
601   /// @return
602   ///     A pointer to this breakpoint's BreakpointOptions.
603   //------------------------------------------------------------------
604   BreakpointOptions *GetOptions();
605
606   //------------------------------------------------------------------
607   /// Returns the BreakpointOptions structure set at the breakpoint level.
608   ///
609   /// Meant to be used by the BreakpointLocation class.
610   ///
611   /// @return
612   ///     A pointer to this breakpoint's BreakpointOptions.
613   //------------------------------------------------------------------
614   const BreakpointOptions *GetOptions() const;
615
616   //------------------------------------------------------------------
617   /// Invoke the callback action when the breakpoint is hit.
618   ///
619   /// Meant to be used by the BreakpointLocation class.
620   ///
621   /// @param[in] context
622   ///     Described the breakpoint event.
623   ///
624   /// @param[in] bp_loc_id
625   ///     Which breakpoint location hit this breakpoint.
626   ///
627   /// @return
628   ///     \b true if the target should stop at this breakpoint and \b false not.
629   //------------------------------------------------------------------
630   bool InvokeCallback(StoppointCallbackContext *context,
631                       lldb::break_id_t bp_loc_id);
632
633   bool IsHardware() const { return m_hardware; }
634
635   lldb::BreakpointResolverSP GetResolver() { return m_resolver_sp; }
636
637   lldb::SearchFilterSP GetSearchFilter() { return m_filter_sp; }
638
639 private: // The target needs to manage adding & removing names.  It will do the
640          // checking for name validity as well.
641   bool AddName(llvm::StringRef new_name);
642
643   void RemoveName(const char *name_to_remove) {
644     if (name_to_remove)
645       m_name_list.erase(name_to_remove);
646   }
647   
648 public:
649   bool MatchesName(const char *name) {
650     return m_name_list.find(name) != m_name_list.end();
651   }
652
653   void GetNames(std::vector<std::string> &names) {
654     names.clear();
655     for (auto name : m_name_list) {
656       names.push_back(name);
657     }
658   }
659
660   //------------------------------------------------------------------
661   /// Set a pre-condition filter that overrides all user provided
662   /// filters/callbacks etc.
663   ///
664   /// Used to define fancy breakpoints that can do dynamic hit detection without
665   /// taking up the condition slot -
666   /// which really belongs to the user anyway...
667   ///
668   /// The Precondition should not continue the target, it should return true if
669   /// the condition says to stop and
670   /// false otherwise.
671   ///
672   //------------------------------------------------------------------
673   void SetPrecondition(BreakpointPreconditionSP precondition_sp) {
674     m_precondition_sp = precondition_sp;
675   }
676
677   bool EvaluatePrecondition(StoppointCallbackContext &context);
678
679   BreakpointPreconditionSP GetPrecondition() { return m_precondition_sp; }
680   
681   // Produces the OR'ed values for all the names assigned to this breakpoint.
682   const BreakpointName::Permissions &GetPermissions() const { 
683       return m_permissions; 
684   }
685
686   BreakpointName::Permissions &GetPermissions() { 
687       return m_permissions; 
688   }
689   
690   bool AllowList() const {
691     return GetPermissions().GetAllowList();
692   }
693   bool AllowDisable() const {
694     return GetPermissions().GetAllowDisable();
695   }
696   bool AllowDelete() const {
697     return GetPermissions().GetAllowDelete();
698   }
699
700 protected:
701   friend class Target;
702   //------------------------------------------------------------------
703   // Protected Methods
704   //------------------------------------------------------------------
705
706   //------------------------------------------------------------------
707   /// Constructors and Destructors
708   /// Only the Target can make a breakpoint, and it owns the breakpoint
709   /// lifespans.
710   /// The constructor takes a filter and a resolver.  Up in Target there are
711   /// convenience
712   /// variants that make breakpoints for some common cases.
713   ///
714   /// @param[in] target
715   ///    The target in which the breakpoint will be set.
716   ///
717   /// @param[in] filter_sp
718   ///    Shared pointer to the search filter that restricts the search domain of
719   ///    the breakpoint.
720   ///
721   /// @param[in] resolver_sp
722   ///    Shared pointer to the resolver object that will determine breakpoint
723   ///    matches.
724   ///
725   /// @param hardware
726   ///    If true, request a hardware breakpoint to be used to implement the
727   ///    breakpoint locations.
728   ///
729   /// @param resolve_indirect_symbols
730   ///    If true, and the address of a given breakpoint location in this
731   ///    breakpoint is set on an
732   ///    indirect symbol (i.e. Symbol::IsIndirect returns true) then the actual
733   ///    breakpoint site will
734   ///    be set on the target of the indirect symbol.
735   //------------------------------------------------------------------
736   // This is the generic constructor
737   Breakpoint(Target &target, lldb::SearchFilterSP &filter_sp,
738              lldb::BreakpointResolverSP &resolver_sp, bool hardware,
739              bool resolve_indirect_symbols = true);
740
741   friend class BreakpointLocation; // To call the following two when determining
742                                    // whether to stop.
743
744   void DecrementIgnoreCount();
745
746   // BreakpointLocation::IgnoreCountShouldStop &
747   // Breakpoint::IgnoreCountShouldStop can only be called once per stop,
748   // and BreakpointLocation::IgnoreCountShouldStop should be tested first, and
749   // if it returns false we should
750   // continue, otherwise we should test Breakpoint::IgnoreCountShouldStop.
751
752   bool IgnoreCountShouldStop();
753
754   void IncrementHitCount() { m_hit_count++; }
755
756   void DecrementHitCount() {
757     assert(m_hit_count > 0);
758     m_hit_count--;
759   }
760
761 private:
762   // This one should only be used by Target to copy breakpoints from target to
763   // target - primarily from the dummy
764   // target to prime new targets.
765   Breakpoint(Target &new_target, Breakpoint &bp_to_copy_from);
766
767   //------------------------------------------------------------------
768   // For Breakpoint only
769   //------------------------------------------------------------------
770   bool m_being_created;
771   bool
772       m_hardware; // If this breakpoint is required to use a hardware breakpoint
773   Target &m_target; // The target that holds this breakpoint.
774   std::unordered_set<std::string> m_name_list; // If not empty, this is the name
775                                                // of this breakpoint (many
776                                                // breakpoints can share the same
777                                                // name.)
778   lldb::SearchFilterSP
779       m_filter_sp; // The filter that constrains the breakpoint's domain.
780   lldb::BreakpointResolverSP
781       m_resolver_sp; // The resolver that defines this breakpoint.
782   BreakpointPreconditionSP m_precondition_sp; // The precondition is a
783                                               // breakpoint-level hit filter
784                                               // that can be used
785   // to skip certain breakpoint hits.  For instance, exception breakpoints
786   // use this to limit the stop to certain exception classes, while leaving
787   // the condition & callback free for user specification.
788   std::unique_ptr<BreakpointOptions>
789       m_options_up; // Settable breakpoint options
790   BreakpointLocationList
791       m_locations; // The list of locations currently found for this breakpoint.
792   std::string m_kind_description;
793   bool m_resolve_indirect_symbols;
794   uint32_t m_hit_count; // Number of times this breakpoint/watchpoint has been
795                         // hit.  This is kept
796   // separately from the locations hit counts, since locations can go away when
797   // their backing library gets unloaded, and we would lose hit counts.
798   BreakpointName::Permissions m_permissions;
799
800   void SendBreakpointChangedEvent(lldb::BreakpointEventType eventKind);
801
802   void SendBreakpointChangedEvent(BreakpointEventData *data);
803
804   DISALLOW_COPY_AND_ASSIGN(Breakpoint);
805 };
806
807 } // namespace lldb_private
808
809 #endif // liblldb_Breakpoint_h_