summaryrefslogtreecommitdiff
path: root/include/lldb/Breakpoint/BreakpointLocationList.h
blob: 01ee5b5dcce9dda4894184ccd338a7d3df969312 (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//===-- BreakpointLocationList.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_BreakpointLocationList_h_
#define liblldb_BreakpointLocationList_h_

#include <map>
#include <mutex>
#include <vector>

#include "lldb/Core/Address.h"
#include "lldb/Utility/Iterable.h"
#include "lldb/lldb-private.h"

namespace lldb_private {

//----------------------------------------------------------------------
/// @class BreakpointLocationList BreakpointLocationList.h
/// "lldb/Breakpoint/BreakpointLocationList.h" This class is used by
/// Breakpoint to manage a list of breakpoint locations, each breakpoint
/// location in the list has a unique ID, and is unique by Address as well.
//----------------------------------------------------------------------
class BreakpointLocationList {
  // Only Breakpoints can make the location list, or add elements to it. This
  // is not just some random collection of locations.  Rather, the act of
  // adding the location to this list sets its ID, and implicitly all the
  // locations have the same breakpoint ID as well.  If you need a generic
  // container for breakpoint locations, use BreakpointLocationCollection.
  friend class Breakpoint;

public:
  virtual ~BreakpointLocationList();

  //------------------------------------------------------------------
  /// Standard "Dump" method.  At present it does nothing.
  //------------------------------------------------------------------
  void Dump(Stream *s) const;

  //------------------------------------------------------------------
  /// Returns a shared pointer to the breakpoint location at address \a addr -
  /// const version.
  ///
  /// @param[in] addr
  ///     The address to look for.
  ///
  /// @result
  ///     A shared pointer to the breakpoint. May contain a nullptr
  ///     pointer if the breakpoint doesn't exist.
  //------------------------------------------------------------------
  const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;

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

  //------------------------------------------------------------------
  /// Returns the breakpoint location id to the breakpoint location at address
  /// \a addr.
  ///
  /// @param[in] addr
  ///     The address to match.
  ///
  /// @result
  ///     The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
  //------------------------------------------------------------------
  lldb::break_id_t FindIDByAddress(const Address &addr);

  //------------------------------------------------------------------
  /// Returns a breakpoint location list of the breakpoint locations in the
  /// module \a module.  This list is allocated, and owned by the caller.
  ///
  /// @param[in] module
  ///     The module to seek in.
  ///
  /// @param[in]
  ///     A breakpoint collection that gets any breakpoint locations
  ///     that match \a module appended to.
  ///
  /// @result
  ///     The number of matches
  //------------------------------------------------------------------
  size_t FindInModule(Module *module,
                      BreakpointLocationCollection &bp_loc_list);

  //------------------------------------------------------------------
  /// Returns a shared pointer to the breakpoint location with index \a i.
  ///
  /// @param[in] i
  ///     The breakpoint location index to seek for.
  ///
  /// @result
  ///     A shared pointer to the breakpoint. May contain a nullptr
  ///     pointer if the breakpoint doesn't exist.
  //------------------------------------------------------------------
  lldb::BreakpointLocationSP GetByIndex(size_t i);

  //------------------------------------------------------------------
  /// Returns a shared pointer to the breakpoint location with index \a i,
  /// const version.
  ///
  /// @param[in] i
  ///     The breakpoint location index to seek for.
  ///
  /// @result
  ///     A shared pointer to the breakpoint. May contain a nullptr
  ///     pointer if the breakpoint doesn't exist.
  //------------------------------------------------------------------
  const lldb::BreakpointLocationSP GetByIndex(size_t i) const;

  //------------------------------------------------------------------
  /// Removes all the locations in this list from their breakpoint site owners
  /// list.
  //------------------------------------------------------------------
  void ClearAllBreakpointSites();

  //------------------------------------------------------------------
  /// Tells all the breakpoint locations in this list to attempt to resolve
  /// any possible breakpoint sites.
  //------------------------------------------------------------------
  void ResolveAllBreakpointSites();

  //------------------------------------------------------------------
  /// Returns the number of breakpoint locations in this list with resolved
  /// breakpoints.
  ///
  /// @result
  ///     Number of qualifying breakpoint locations.
  //------------------------------------------------------------------
  size_t GetNumResolvedLocations() const;

  //------------------------------------------------------------------
  /// Returns the number hit count of all locations in this list.
  ///
  /// @result
  ///     Hit count of all locations in this list.
  //------------------------------------------------------------------
  uint32_t GetHitCount() const;

  //------------------------------------------------------------------
  /// Enquires of the breakpoint location in this list with ID \a breakID
  /// whether we should stop.
  ///
  /// @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 this breakpoint location list.
  ///
  /// @result
  ///     The number of elements.
  //------------------------------------------------------------------
  size_t GetSize() const { return m_locations.size(); }

  //------------------------------------------------------------------
  /// Print a description of the breakpoint locations in this list to the
  /// stream \a s.
  ///
  /// @param[in] s
  ///     The stream to which to print the description.
  ///
  /// @param[in] level
  ///     The description level that indicates the detail level to
  ///     provide.
  ///
  /// @see lldb::DescriptionLevel
  //------------------------------------------------------------------
  void GetDescription(Stream *s, lldb::DescriptionLevel level);

protected:
  //------------------------------------------------------------------
  /// This is the standard constructor.
  ///
  /// It creates an empty breakpoint location list. It is protected here
  /// because only Breakpoints are allowed to create the breakpoint location
  /// list.
  //------------------------------------------------------------------
  BreakpointLocationList(Breakpoint &owner);

  //------------------------------------------------------------------
  /// Add the breakpoint \a bp_loc_sp to the list.
  ///
  /// @param[in] bp_sp
  ///     Shared pointer to the breakpoint location that will get
  ///     added to the list.
  ///
  /// @result
  ///     Returns breakpoint location id.
  //------------------------------------------------------------------
  lldb::BreakpointLocationSP Create(const Address &addr,
                                    bool resolve_indirect_symbols);

  void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);

  void StopRecordingNewLocations();

  lldb::BreakpointLocationSP AddLocation(const Address &addr,
                                         bool resolve_indirect_symbols,
                                         bool *new_location = nullptr);

  void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
                    lldb::BreakpointLocationSP from_location_sp);

  bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
  
  void RemoveLocationByIndex(size_t idx);

  void RemoveInvalidLocations(const ArchSpec &arch);

  void Compact();

  typedef std::vector<lldb::BreakpointLocationSP> collection;
  typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
                   Address::ModulePointerAndOffsetLessThanFunctionObject>
      addr_map;

  Breakpoint &m_owner;
  collection m_locations; // Vector of locations, sorted by ID
  addr_map m_address_to_location;
  mutable std::recursive_mutex m_mutex;
  lldb::break_id_t m_next_id;
  BreakpointLocationCollection *m_new_location_recorder;

public:
  typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
                          vector_adapter>
      BreakpointLocationIterable;

  BreakpointLocationIterable BreakpointLocations() {
    return BreakpointLocationIterable(m_locations);
  }
};

} // namespace lldb_private

#endif // liblldb_BreakpointLocationList_h_