xref: /openbsd-src/gnu/llvm/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1061da546Spatrick //===-- BreakpointLocationCollection.h --------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9dda28197Spatrick #ifndef LLDB_BREAKPOINT_BREAKPOINTLOCATIONCOLLECTION_H
10dda28197Spatrick #define LLDB_BREAKPOINT_BREAKPOINTLOCATIONCOLLECTION_H
11061da546Spatrick 
12061da546Spatrick #include <mutex>
13061da546Spatrick #include <vector>
14061da546Spatrick 
15061da546Spatrick #include "lldb/Utility/Iterable.h"
16061da546Spatrick #include "lldb/lldb-private.h"
17061da546Spatrick 
18061da546Spatrick namespace lldb_private {
19061da546Spatrick 
20061da546Spatrick class BreakpointLocationCollection {
21061da546Spatrick public:
22061da546Spatrick   BreakpointLocationCollection();
23061da546Spatrick 
24061da546Spatrick   ~BreakpointLocationCollection();
25061da546Spatrick 
26061da546Spatrick   BreakpointLocationCollection &operator=(const BreakpointLocationCollection &rhs);
27061da546Spatrick 
28061da546Spatrick   /// Add the breakpoint \a bp_loc_sp to the list.
29061da546Spatrick   ///
30061da546Spatrick   /// \param[in] bp_loc_sp
31061da546Spatrick   ///     Shared pointer to the breakpoint location that will get added
32061da546Spatrick   ///     to the list.
33061da546Spatrick   void Add(const lldb::BreakpointLocationSP &bp_loc_sp);
34061da546Spatrick 
35061da546Spatrick   /// Removes the breakpoint location given by \b breakID from this
36061da546Spatrick   /// list.
37061da546Spatrick   ///
38061da546Spatrick   /// \param[in] break_id
39061da546Spatrick   ///     The breakpoint index to remove.
40061da546Spatrick   ///
41061da546Spatrick   /// \param[in] break_loc_id
42061da546Spatrick   ///     The breakpoint location index in break_id to remove.
43061da546Spatrick   ///
44061da546Spatrick   /// \result
45061da546Spatrick   ///     \b true if the breakpoint was in the list.
46061da546Spatrick   bool Remove(lldb::break_id_t break_id, lldb::break_id_t break_loc_id);
47061da546Spatrick 
48061da546Spatrick   /// Returns a shared pointer to the breakpoint location with id \a
49061da546Spatrick   /// breakID.
50061da546Spatrick   ///
51061da546Spatrick   /// \param[in] break_id
52061da546Spatrick   ///     The breakpoint  ID to seek for.
53061da546Spatrick   ///
54061da546Spatrick   /// \param[in] break_loc_id
55061da546Spatrick   ///     The breakpoint location ID in \a break_id to seek for.
56061da546Spatrick   ///
57061da546Spatrick   /// \result
58061da546Spatrick   ///     A shared pointer to the breakpoint.  May contain a NULL
59061da546Spatrick   ///     pointer if the breakpoint doesn't exist.
60061da546Spatrick   lldb::BreakpointLocationSP FindByIDPair(lldb::break_id_t break_id,
61061da546Spatrick                                           lldb::break_id_t break_loc_id);
62061da546Spatrick 
63061da546Spatrick   /// Returns a shared pointer to the breakpoint location with id \a
64061da546Spatrick   /// breakID, const version.
65061da546Spatrick   ///
66061da546Spatrick   /// \param[in] break_id
67061da546Spatrick   ///     The breakpoint location ID to seek for.
68061da546Spatrick   ///
69061da546Spatrick   /// \param[in] break_loc_id
70061da546Spatrick   ///     The breakpoint location ID in \a break_id to seek for.
71061da546Spatrick   ///
72061da546Spatrick   /// \result
73061da546Spatrick   ///     A shared pointer to the breakpoint.  May contain a NULL
74061da546Spatrick   ///     pointer if the breakpoint doesn't exist.
75061da546Spatrick   const lldb::BreakpointLocationSP
76061da546Spatrick   FindByIDPair(lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const;
77061da546Spatrick 
78061da546Spatrick   /// Returns a shared pointer to the breakpoint location with index
79061da546Spatrick   /// \a i.
80061da546Spatrick   ///
81061da546Spatrick   /// \param[in] i
82061da546Spatrick   ///     The breakpoint location index to seek for.
83061da546Spatrick   ///
84061da546Spatrick   /// \result
85061da546Spatrick   ///     A shared pointer to the breakpoint.  May contain a NULL
86061da546Spatrick   ///     pointer if the breakpoint doesn't exist.
87061da546Spatrick   lldb::BreakpointLocationSP GetByIndex(size_t i);
88061da546Spatrick 
89061da546Spatrick   /// Returns a shared pointer to the breakpoint location with index
90061da546Spatrick   /// \a i, const version.
91061da546Spatrick   ///
92061da546Spatrick   /// \param[in] i
93061da546Spatrick   ///     The breakpoint location index to seek for.
94061da546Spatrick   ///
95061da546Spatrick   /// \result
96061da546Spatrick   ///     A shared pointer to the breakpoint.  May contain a NULL
97061da546Spatrick   ///     pointer if the breakpoint doesn't exist.
98061da546Spatrick   const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
99061da546Spatrick 
100061da546Spatrick   /// Returns the number of elements in this breakpoint location list.
101061da546Spatrick   ///
102061da546Spatrick   /// \result
103061da546Spatrick   ///     The number of elements.
GetSize()104061da546Spatrick   size_t GetSize() const { return m_break_loc_collection.size(); }
105061da546Spatrick 
106061da546Spatrick   /// Enquires of all the breakpoint locations in this list whether
107061da546Spatrick   /// we should stop at a hit at \a breakID.
108061da546Spatrick   ///
109061da546Spatrick   /// \param[in] context
110061da546Spatrick   ///    This contains the information about this stop.
111061da546Spatrick   ///
112061da546Spatrick   /// \return
113061da546Spatrick   ///    \b true if we should stop, \b false otherwise.
114061da546Spatrick   bool ShouldStop(StoppointCallbackContext *context);
115061da546Spatrick 
116061da546Spatrick   /// Print a description of the breakpoint locations in this list
117061da546Spatrick   /// to the stream \a s.
118061da546Spatrick   ///
119061da546Spatrick   /// \param[in] s
120061da546Spatrick   ///     The stream to which to print the description.
121061da546Spatrick   ///
122061da546Spatrick   /// \param[in] level
123061da546Spatrick   ///     The description level that indicates the detail level to
124061da546Spatrick   ///     provide.
125061da546Spatrick   ///
126061da546Spatrick   /// \see lldb::DescriptionLevel
127061da546Spatrick   void GetDescription(Stream *s, lldb::DescriptionLevel level);
128061da546Spatrick 
129061da546Spatrick   /// Check whether this collection of breakpoint locations have any
130061da546Spatrick   /// thread specifiers, and if yes, is \a thread_id contained in any
131061da546Spatrick   /// of these specifiers.
132061da546Spatrick   ///
133061da546Spatrick   /// \param[in] thread
134061da546Spatrick   ///     The thread against which to test.
135061da546Spatrick   ///
136061da546Spatrick   /// return
137061da546Spatrick   ///     \b true if the collection contains at least one location that
138061da546Spatrick   ///     would be valid for this thread, false otherwise.
139*be691f3bSpatrick   bool ValidForThisThread(Thread &thread);
140061da546Spatrick 
141061da546Spatrick   /// Tell whether ALL the breakpoints in the location collection are internal.
142061da546Spatrick   ///
143061da546Spatrick   /// \result
144061da546Spatrick   ///     \b true if all breakpoint locations are owned by internal breakpoints,
145061da546Spatrick   ///     \b false otherwise.
146061da546Spatrick   bool IsInternal() const;
147061da546Spatrick 
148061da546Spatrick protected:
149061da546Spatrick   // Classes that inherit from BreakpointLocationCollection can see and modify
150061da546Spatrick   // these
151061da546Spatrick 
152061da546Spatrick private:
153061da546Spatrick   // For BreakpointLocationCollection only
154061da546Spatrick 
155061da546Spatrick   typedef std::vector<lldb::BreakpointLocationSP> collection;
156061da546Spatrick 
157061da546Spatrick   collection::iterator GetIDPairIterator(lldb::break_id_t break_id,
158061da546Spatrick                                          lldb::break_id_t break_loc_id);
159061da546Spatrick 
160061da546Spatrick   collection::const_iterator
161061da546Spatrick   GetIDPairConstIterator(lldb::break_id_t break_id,
162061da546Spatrick                          lldb::break_id_t break_loc_id) const;
163061da546Spatrick 
164061da546Spatrick   collection m_break_loc_collection;
165061da546Spatrick   mutable std::mutex m_collection_mutex;
166061da546Spatrick 
167061da546Spatrick public:
168061da546Spatrick   typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
169061da546Spatrick                           vector_adapter>
170061da546Spatrick       BreakpointLocationCollectionIterable;
BreakpointLocations()171061da546Spatrick   BreakpointLocationCollectionIterable BreakpointLocations() {
172061da546Spatrick     return BreakpointLocationCollectionIterable(m_break_loc_collection);
173061da546Spatrick   }
174061da546Spatrick };
175061da546Spatrick 
176061da546Spatrick } // namespace lldb_private
177061da546Spatrick 
178dda28197Spatrick #endif // LLDB_BREAKPOINT_BREAKPOINTLOCATIONCOLLECTION_H
179