BreakpointList.h revision 3c7b5b9f83cae58ca366db2bba37dc09485f7dcc
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    virtual lldb::break_id_t
50    Add (lldb::BreakpointSP& bp_sp);
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    GetBreakpointByIndex (uint32_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    GetBreakpointByIndex (uint32_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 { return m_breakpoints.size(); }
118
119    //------------------------------------------------------------------
120    /// Removes the breakpoint given by \b breakID from this list.
121    ///
122    /// @param[in] breakID
123    ///   The breakpoint index to remove.
124    ///
125    /// @result
126    ///   \b true if the breakpoint \a breakID was in the list.
127    //------------------------------------------------------------------
128    bool
129    Remove (lldb::break_id_t breakID);
130
131    void
132    SetEnabledAll (bool enabled);
133
134    //------------------------------------------------------------------
135    /// Removes all the breakpoints from this list.
136    //------------------------------------------------------------------
137    void
138    RemoveAll ();
139
140    //------------------------------------------------------------------
141    /// Tell all the breakpoints to update themselves due to a change in the
142    /// modules in \a module_list.  \a added says whether the module was loaded
143    /// or unloaded.
144    ///
145    /// @param[in] module_list
146    ///   The module list that has changed.
147    ///
148    /// @param[in] added
149    ///   \b true if the modules are loaded, \b false if unloaded.
150    //------------------------------------------------------------------
151    void
152    UpdateBreakpoints (ModuleList &module_list, bool added);
153
154    void
155    ClearAllBreakpointSites ();
156
157    //------------------------------------------------------------------
158    /// Sets the passed in Locker to hold the Breakpoint List mutex.
159    ///
160    /// @param[in] locker
161    ///   The locker object that is set.
162    //------------------------------------------------------------------
163    void
164    GetListMutex (lldb_private::Mutex::Locker &locker);
165
166protected:
167    typedef std::list<lldb::BreakpointSP> bp_collection;
168
169    bp_collection::iterator
170    GetBreakpointIDIterator(lldb::break_id_t breakID);
171
172    bp_collection::const_iterator
173    GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
174
175    mutable Mutex m_mutex;
176    bp_collection m_breakpoints;  // The breakpoint list, currently a list.
177    lldb::break_id_t m_next_break_id;
178    bool m_is_internal;
179
180private:
181    DISALLOW_COPY_AND_ASSIGN (BreakpointList);
182};
183
184} // namespace lldb_private
185
186#endif  // liblldb_BreakpointList_h_
187