aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Breakpoint/BreakpointSiteList.h
blob: 0d4dafc4baabb4d15a4a1b4e1b9e74b1128373e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//===-- BreakpointSiteList.h ------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_BreakpointSiteList_h_
#define liblldb_BreakpointSiteList_h_

// C Includes
// C++ Includes
#include <map>
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointSite.h"
#include "lldb/Host/Mutex.h"

namespace lldb_private {

//----------------------------------------------------------------------
/// @class BreakpointSiteList BreakpointSiteList.h "lldb/Breakpoint/BreakpointSiteList.h"
/// @brief Class that manages lists of BreakpointSite shared pointers.
//----------------------------------------------------------------------
class BreakpointSiteList
{
// At present Process directly accesses the map of BreakpointSites so it can
// do quick lookups into the map (using GetMap).
// FIXME: Find a better interface for this.
friend class Process;

public:
    //------------------------------------------------------------------
    /// Default constructor makes an empty list.
    //------------------------------------------------------------------
    BreakpointSiteList();

    //------------------------------------------------------------------
    /// Destructor, currently does nothing.
    //------------------------------------------------------------------
    ~BreakpointSiteList();

    //------------------------------------------------------------------
    /// Add a BreakpointSite to the list.
    ///
    /// @param[in] bp_site_sp
    ///    A shared pointer to a breakpoint site being added to the list.
    ///
    /// @return
    ///    The ID of the BreakpointSite in the list.
    //------------------------------------------------------------------
    lldb::break_id_t
    Add (const lldb::BreakpointSiteSP& bp_site_sp);

    //------------------------------------------------------------------
    /// Standard Dump routine, doesn't do anything at present.
    /// @param[in] s
    ///     Stream into which to dump the description.
    //------------------------------------------------------------------
    void
    Dump (Stream *s) const;

    //------------------------------------------------------------------
    /// Returns a shared pointer to the breakpoint site at address
    /// \a addr.
    ///
    /// @param[in] addr
    ///     The address to look for.
    ///
    /// @result
    ///     A shared pointer to the breakpoint site. May contain a NULL
    ///     pointer if no breakpoint site exists with a matching address.
    //------------------------------------------------------------------
    lldb::BreakpointSiteSP
    FindByAddress (lldb::addr_t addr);

    //------------------------------------------------------------------
    /// Returns a shared pointer to the breakpoint site with id \a breakID.
    ///
    /// @param[in] breakID
    ///   The breakpoint site ID to seek for.
    ///
    /// @result
    ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if the
    ///   breakpoint doesn't exist.
    //------------------------------------------------------------------
    lldb::BreakpointSiteSP
    FindByID (lldb::break_id_t breakID);

    //------------------------------------------------------------------
    /// Returns a shared pointer to the breakpoint site with id \a breakID - const version.
    ///
    /// @param[in] breakID
    ///   The breakpoint site ID to seek for.
    ///
    /// @result
    ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if the
    ///   breakpoint doesn't exist.
    //------------------------------------------------------------------
    const lldb::BreakpointSiteSP
    FindByID (lldb::break_id_t breakID) const;

    //------------------------------------------------------------------
    /// Returns the breakpoint site id to the breakpoint site at address \a addr.
    ///
    /// @param[in] addr
    ///   The address to match.
    ///
    /// @result
    ///   The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
    //------------------------------------------------------------------
    lldb::break_id_t
    FindIDByAddress (lldb::addr_t addr);
    
    //------------------------------------------------------------------
    /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
    //  as one of its owners.
    ///
    /// @param[in] bp_site_id
    ///   The breakpoint site id to query.
    ///
    /// @param[in] bp_id
    ///   The breakpoint id to look for in \a bp_site_id.
    ///
    /// @result
    ///   True if \a bp_site_id exists in the site list AND \a bp_id is one of the
    ///   owners of that site.
    //------------------------------------------------------------------
    bool
    BreakpointSiteContainsBreakpoint (lldb::break_id_t bp_site_id, lldb::break_id_t bp_id);

    void
    ForEach (std::function <void(BreakpointSite *)> const &callback);

    //------------------------------------------------------------------
    /// Removes the breakpoint site given by \b breakID from this list.
    ///
    /// @param[in] breakID
    ///   The breakpoint site index to remove.
    ///
    /// @result
    ///   \b true if the breakpoint site \a breakID was in the list.
    //------------------------------------------------------------------
    bool
    Remove (lldb::break_id_t breakID);

    //------------------------------------------------------------------
    /// Removes the breakpoint site at address \a addr from this list.
    ///
    /// @param[in] addr
    ///   The address from which to remove a breakpoint site.
    ///
    /// @result
    ///   \b true if \a addr had a breakpoint site to remove from the list.
    //------------------------------------------------------------------
    bool
    RemoveByAddress (lldb::addr_t addr);
    
    bool
    FindInRange (lldb::addr_t lower_bound, lldb::addr_t upper_bound, BreakpointSiteList &bp_site_list) const;

    typedef void (*BreakpointSiteSPMapFunc) (lldb::BreakpointSiteSP &bp, void *baton);

    //------------------------------------------------------------------
    /// Enquires of the breakpoint site on in this list with ID \a breakID whether
    /// we should stop for the breakpoint or not.
    ///
    /// @param[in] context
    ///    This contains the information about this stop.
    ///
    /// @param[in] breakID
    ///    This break ID that we hit.
    ///
    /// @return
    ///    \b true if we should stop, \b false otherwise.
    //------------------------------------------------------------------
    bool
    ShouldStop (StoppointCallbackContext *context, lldb::break_id_t breakID);

    //------------------------------------------------------------------
    /// Returns the number of elements in the list.
    ///
    /// @result
    ///   The number of elements.
    //------------------------------------------------------------------
    size_t
    GetSize() const
    {
        Mutex::Locker locker(m_mutex);
        return m_bp_site_list.size();
    }

    bool
    IsEmpty() const
    {
        Mutex::Locker locker(m_mutex);
        return m_bp_site_list.empty();
    }
protected:
    typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;

    collection::iterator
    GetIDIterator(lldb::break_id_t breakID);

    collection::const_iterator
    GetIDConstIterator(lldb::break_id_t breakID) const;

    mutable Mutex m_mutex;
    collection m_bp_site_list;  // The breakpoint site list.
};

} // namespace lldb_private

#endif  // liblldb_BreakpointSiteList_h_