reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
//===-- BreakpointLocationCollection.h --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_BreakpointLocationCollection_h_
#define liblldb_BreakpointLocationCollection_h_

#include <mutex>
#include <vector>

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

namespace lldb_private {

class BreakpointLocationCollection {
public:
  BreakpointLocationCollection();

  ~BreakpointLocationCollection();
  
  BreakpointLocationCollection &operator=(const BreakpointLocationCollection &rhs);

  /// 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.
  void Add(const lldb::BreakpointLocationSP &bp_loc_sp);

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

  /// Returns a shared pointer to the breakpoint location with id \a
  /// breakID.
  ///
  /// \param[in] break_id
  ///     The breakpoint  ID to seek for.
  ///
  /// \param[in] break_loc_id
  ///     The breakpoint location ID in \a break_id to seek for.
  ///
  /// \result
  ///     A shared pointer to the breakpoint.  May contain a NULL
  ///     pointer if the breakpoint doesn't exist.
  lldb::BreakpointLocationSP FindByIDPair(lldb::break_id_t break_id,
                                          lldb::break_id_t break_loc_id);

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

  /// 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 NULL
  ///     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 NULL
  ///     pointer if the breakpoint doesn't exist.
  const lldb::BreakpointLocationSP GetByIndex(size_t i) const;

  /// Returns the number of elements in this breakpoint location list.
  ///
  /// \result
  ///     The number of elements.
  size_t GetSize() const { return m_break_loc_collection.size(); }

  /// Enquires of all the breakpoint locations in this list whether
  /// we should stop at a hit at \a breakID.
  ///
  /// \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);

  /// 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);

  /// Check whether this collection of breakpoint locations have any
  /// thread specifiers, and if yes, is \a thread_id contained in any
  /// of these specifiers.
  ///
  /// \param[in] thread
  ///     The thread against which to test.
  ///
  /// return
  ///     \b true if the collection contains at least one location that
  ///     would be valid for this thread, false otherwise.
  bool ValidForThisThread(Thread *thread);

  /// Tell whether ALL the breakpoints in the location collection are internal.
  ///
  /// \result
  ///     \b true if all breakpoint locations are owned by internal breakpoints,
  ///     \b false otherwise.
  bool IsInternal() const;

protected:
  // Classes that inherit from BreakpointLocationCollection can see and modify
  // these

private:
  // For BreakpointLocationCollection only

  typedef std::vector<lldb::BreakpointLocationSP> collection;

  collection::iterator GetIDPairIterator(lldb::break_id_t break_id,
                                         lldb::break_id_t break_loc_id);

  collection::const_iterator
  GetIDPairConstIterator(lldb::break_id_t break_id,
                         lldb::break_id_t break_loc_id) const;

  collection m_break_loc_collection;
  mutable std::mutex m_collection_mutex;

public:
  typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
                          vector_adapter>
      BreakpointLocationCollectionIterable;
  BreakpointLocationCollectionIterable BreakpointLocations() {
    return BreakpointLocationCollectionIterable(m_break_loc_collection);
  }
};

} // namespace lldb_private

#endif // liblldb_BreakpointLocationCollection_h_