BreakpointList.h revision 36da2aa6dc5ad9994b638ed09eb81c44cc05540b
1//===-- BreakpointList.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_BreakpointList_h_
11#define liblldb_BreakpointList_h_
12
13// C Includes
14// C++ Includes
15#include <list>
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Host/Mutex.h"
20
21namespace lldb_private {
22
23//----------------------------------------------------------------------
24/// @class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
25/// @brief This class manages a list of breakpoints.
26//----------------------------------------------------------------------
27
28//----------------------------------------------------------------------
29/// General Outline:
30/// Allows adding and removing breakpoints and find by ID and index.
31//----------------------------------------------------------------------
32
33class BreakpointList
34{
35public:
36    BreakpointList (bool is_internal);
37
38    ~BreakpointList();
39
40    //------------------------------------------------------------------
41    /// Add the breakpoint \a bp_sp to the list.
42    ///
43    /// @param[in] bp_sp
44    ///   Shared pointer to the breakpoint that will get added to the list.
45    ///
46    /// @result
47    ///   Returns breakpoint id.
48    //------------------------------------------------------------------
49    lldb::break_id_t
50    Add (lldb::BreakpointSP& bp_sp, bool notify);
51
52    //------------------------------------------------------------------
53    /// Standard "Dump" method.  At present it does nothing.
54    //------------------------------------------------------------------
55    void
56    Dump (Stream *s) const;
57
58    //------------------------------------------------------------------
59    /// Returns a shared pointer to the breakpoint with id \a breakID.
60    ///
61    /// @param[in] breakID
62    ///   The breakpoint ID to seek for.
63    ///
64    /// @result
65    ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
66    ///   breakpoint doesn't exist.
67    //------------------------------------------------------------------
68    lldb::BreakpointSP
69    FindBreakpointByID (lldb::break_id_t breakID);
70
71    //------------------------------------------------------------------
72    /// Returns a shared pointer to the breakpoint with id \a breakID.  Const version.
73    ///
74    /// @param[in] breakID
75    ///   The breakpoint ID to seek for.
76    ///
77    /// @result
78    ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
79    ///   breakpoint doesn't exist.
80    //------------------------------------------------------------------
81    const lldb::BreakpointSP
82    FindBreakpointByID (lldb::break_id_t breakID) const;
83
84    //------------------------------------------------------------------
85    /// Returns a shared pointer to the breakpoint with index \a i.
86    ///
87    /// @param[in] i
88    ///   The breakpoint index to seek for.
89    ///
90    /// @result
91    ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
92    ///   breakpoint doesn't exist.
93    //------------------------------------------------------------------
94    lldb::BreakpointSP
95    GetBreakpointAtIndex (size_t i);
96
97    //------------------------------------------------------------------
98    /// Returns a shared pointer to the breakpoint with index \a i, const version
99    ///
100    /// @param[in] i
101    ///   The breakpoint index to seek for.
102    ///
103    /// @result
104    ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
105    ///   breakpoint doesn't exist.
106    //------------------------------------------------------------------
107    const lldb::BreakpointSP
108    GetBreakpointAtIndex (size_t i) const;
109
110    //------------------------------------------------------------------
111    /// Returns the number of elements in this breakpoint list.
112    ///
113    /// @result
114    ///   The number of elements.
115    //------------------------------------------------------------------
116    size_t
117    GetSize() const
118    {
119        Mutex::Locker locker(m_mutex);
120        return m_breakpoints.size();
121    }
122
123    //------------------------------------------------------------------
124    /// Removes the breakpoint given by \b breakID from this list.
125    ///
126    /// @param[in] breakID
127    ///   The breakpoint index to remove.
128    ///
129    /// @result
130    ///   \b true if the breakpoint \a breakID was in the list.
131    //------------------------------------------------------------------
132    bool
133    Remove (lldb::break_id_t breakID, bool notify);
134
135    void
136    SetEnabledAll (bool enabled);
137
138    //------------------------------------------------------------------
139    /// Removes all the breakpoints from this list.
140    //------------------------------------------------------------------
141    void
142    RemoveAll (bool notify);
143
144    //------------------------------------------------------------------
145    /// Tell all the breakpoints to update themselves due to a change in the
146    /// modules in \a module_list.  \a added says whether the module was loaded
147    /// or unloaded.
148    ///
149    /// @param[in] module_list
150    ///   The module list that has changed.
151    ///
152    /// @param[in] added
153    ///   \b true if the modules are loaded, \b false if unloaded.
154    //------------------------------------------------------------------
155    void
156    UpdateBreakpoints (ModuleList &module_list, bool added);
157
158    void
159    UpdateBreakpointsWhenModuleIsReplaced (lldb::ModuleSP old_module_sp, lldb::ModuleSP new_module_sp);
160
161    void
162    ClearAllBreakpointSites ();
163
164    //------------------------------------------------------------------
165    /// Sets the passed in Locker to hold the Breakpoint List mutex.
166    ///
167    /// @param[in] locker
168    ///   The locker object that is set.
169    //------------------------------------------------------------------
170    void
171    GetListMutex (lldb_private::Mutex::Locker &locker);
172
173protected:
174    typedef std::list<lldb::BreakpointSP> bp_collection;
175
176    bp_collection::iterator
177    GetBreakpointIDIterator(lldb::break_id_t breakID);
178
179    bp_collection::const_iterator
180    GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
181
182    mutable Mutex m_mutex;
183    bp_collection m_breakpoints;  // The breakpoint list, currently a list.
184    lldb::break_id_t m_next_break_id;
185    bool m_is_internal;
186
187private:
188    DISALLOW_COPY_AND_ASSIGN (BreakpointList);
189};
190
191} // namespace lldb_private
192
193#endif  // liblldb_BreakpointList_h_
194