1 //===-- SBBreakpoint.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_API_SBBREAKPOINT_H
10 #define LLDB_API_SBBREAKPOINT_H
11 
12 #include "lldb/API/SBDefines.h"
13 
14 class SBBreakpointListImpl;
15 
16 namespace lldb_private {
17 class ScriptInterpreter;
18 namespace python {
19 class SWIGBridge;
20 }
21 } // namespace lldb_private
22 
23 namespace lldb {
24 
25 class LLDB_API SBBreakpoint {
26 public:
27 
28   SBBreakpoint();
29 
30   SBBreakpoint(const lldb::SBBreakpoint &rhs);
31 
32   ~SBBreakpoint();
33 
34   const lldb::SBBreakpoint &operator=(const lldb::SBBreakpoint &rhs);
35 
36   // Tests to see if the opaque breakpoint object in this object matches the
37   // opaque breakpoint object in "rhs".
38   bool operator==(const lldb::SBBreakpoint &rhs);
39 
40   bool operator!=(const lldb::SBBreakpoint &rhs);
41 
42   break_id_t GetID() const;
43 
44   explicit operator bool() const;
45 
46   bool IsValid() const;
47 
48   void ClearAllBreakpointSites();
49 
50   lldb::SBTarget GetTarget() const;
51 
52   lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr);
53 
54   lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr);
55 
56   lldb::SBBreakpointLocation FindLocationByID(lldb::break_id_t bp_loc_id);
57 
58   lldb::SBBreakpointLocation GetLocationAtIndex(uint32_t index);
59 
60   void SetEnabled(bool enable);
61 
62   bool IsEnabled();
63 
64   void SetOneShot(bool one_shot);
65 
66   bool IsOneShot() const;
67 
68   bool IsInternal();
69 
70   uint32_t GetHitCount() const;
71 
72   void SetIgnoreCount(uint32_t count);
73 
74   uint32_t GetIgnoreCount() const;
75 
76   void SetCondition(const char *condition);
77 
78   const char *GetCondition();
79 
80   void SetAutoContinue(bool auto_continue);
81 
82   bool GetAutoContinue();
83 
84   void SetThreadID(lldb::tid_t sb_thread_id);
85 
86   lldb::tid_t GetThreadID();
87 
88   void SetThreadIndex(uint32_t index);
89 
90   uint32_t GetThreadIndex() const;
91 
92   void SetThreadName(const char *thread_name);
93 
94   const char *GetThreadName() const;
95 
96   void SetQueueName(const char *queue_name);
97 
98   const char *GetQueueName() const;
99 
100 #ifndef SWIG
101   void SetCallback(SBBreakpointHitCallback callback, void *baton);
102 #endif
103 
104   void SetScriptCallbackFunction(const char *callback_function_name);
105 
106   SBError SetScriptCallbackFunction(const char *callback_function_name,
107                                  SBStructuredData &extra_args);
108 
109   void SetCommandLineCommands(SBStringList &commands);
110 
111   bool GetCommandLineCommands(SBStringList &commands);
112 
113   SBError SetScriptCallbackBody(const char *script_body_text);
114 
115   LLDB_DEPRECATED_FIXME("Doesn't provide error handling",
116                         "AddNameWithErrorHandling")
117   bool AddName(const char *new_name);
118 
119   SBError AddNameWithErrorHandling(const char *new_name);
120 
121   void RemoveName(const char *name_to_remove);
122 
123   bool MatchesName(const char *name);
124 
125   void GetNames(SBStringList &names);
126 
127   size_t GetNumResolvedLocations() const;
128 
129   size_t GetNumLocations() const;
130 
131   bool GetDescription(lldb::SBStream &description);
132 
133   bool GetDescription(lldb::SBStream &description, bool include_locations);
134 
135   static bool EventIsBreakpointEvent(const lldb::SBEvent &event);
136 
137   static lldb::BreakpointEventType
138   GetBreakpointEventTypeFromEvent(const lldb::SBEvent &event);
139 
140   static lldb::SBBreakpoint GetBreakpointFromEvent(const lldb::SBEvent &event);
141 
142   static lldb::SBBreakpointLocation
143   GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event,
144                                         uint32_t loc_idx);
145 
146   static uint32_t
147   GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event_sp);
148 
149   bool IsHardware() const;
150 
151   // Can only be called from a ScriptedBreakpointResolver...
152   SBError
153   AddLocation(SBAddress &address);
154 
155   SBStructuredData SerializeToStructuredData();
156 
157 private:
158   friend class SBBreakpointList;
159   friend class SBBreakpointLocation;
160   friend class SBBreakpointName;
161   friend class SBTarget;
162 
163   friend class lldb_private::ScriptInterpreter;
164   friend class lldb_private::python::SWIGBridge;
165 
166   SBBreakpoint(const lldb::BreakpointSP &bp_sp);
167 
168   lldb::BreakpointSP GetSP() const;
169 
170   lldb::BreakpointWP m_opaque_wp;
171 };
172 
173 class LLDB_API SBBreakpointList {
174 public:
175   SBBreakpointList(SBTarget &target);
176 
177   ~SBBreakpointList();
178 
179   size_t GetSize() const;
180 
181   SBBreakpoint GetBreakpointAtIndex(size_t idx);
182 
183   SBBreakpoint FindBreakpointByID(lldb::break_id_t);
184 
185   void Append(const SBBreakpoint &sb_bkpt);
186 
187   bool AppendIfUnique(const SBBreakpoint &sb_bkpt);
188 
189   void AppendByID(lldb::break_id_t id);
190 
191   void Clear();
192 
193 protected:
194   friend class SBTarget;
195 
196   void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list);
197 
198 private:
199   std::shared_ptr<SBBreakpointListImpl> m_opaque_sp;
200 };
201 
202 } // namespace lldb
203 
204 #endif // LLDB_API_SBBREAKPOINT_H
205