blob: 190c9b90dd66ab21f13a2786a7ff2fd45a425c09 [file] [log] [blame]
Johnny Chen5de6a792011-07-18 21:30:21 +00001//===-- SWIG Interface for SBBreakpoint -------------------------*- 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
10namespace lldb {
11
12%feature("docstring",
13"Represents a logical breakpoint and its associated settings.
14
15For example (from test/functionalities/breakpoint/breakpoint_ignore_count/
16TestBreakpointIgnoreCount.py),
17
18 def breakpoint_ignore_count_python(self):
19 '''Use Python APIs to set breakpoint ignore count.'''
20 exe = os.path.join(os.getcwd(), 'a.out')
21
22 # Create a target by the debugger.
23 target = self.dbg.CreateTarget(exe)
24 self.assertTrue(target, VALID_TARGET)
25
26 # Now create a breakpoint on main.c by name 'c'.
27 breakpoint = target.BreakpointCreateByName('c', 'a.out')
28 self.assertTrue(breakpoint and
29 breakpoint.GetNumLocations() == 1,
30 VALID_BREAKPOINT)
31
32 # Get the breakpoint location from breakpoint after we verified that,
33 # indeed, it has one location.
34 location = breakpoint.GetLocationAtIndex(0)
35 self.assertTrue(location and
36 location.IsEnabled(),
37 VALID_BREAKPOINT_LOCATION)
38
39 # Set the ignore count on the breakpoint location.
40 location.SetIgnoreCount(2)
41 self.assertTrue(location.GetIgnoreCount() == 2,
42 'SetIgnoreCount() works correctly')
43
44 # Now launch the process, and do not stop at entry point.
45 process = target.LaunchSimple(None, None, os.getcwd())
46 self.assertTrue(process, PROCESS_IS_VALID)
47
48 # Frame#0 should be on main.c:37, frame#1 should be on main.c:25, and
49 # frame#2 should be on main.c:48.
50 #lldbutil.print_stacktraces(process)
51 from lldbutil import get_stopped_thread
52 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
53 self.assertTrue(thread != None, 'There should be a thread stopped due to breakpoint')
54 frame0 = thread.GetFrameAtIndex(0)
55 frame1 = thread.GetFrameAtIndex(1)
56 frame2 = thread.GetFrameAtIndex(2)
57 self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and
58 frame1.GetLineEntry().GetLine() == self.line3 and
59 frame2.GetLineEntry().GetLine() == self.line4,
60 STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT)
61
62 # The hit count for the breakpoint should be 3.
63 self.assertTrue(breakpoint.GetHitCount() == 3)
64
65 process.Continue()
66
Johnny Chenf74cb502011-07-18 23:11:07 +000067SBBreakpoint supports breakpoint location iteration, for example,
Johnny Chen5de6a792011-07-18 21:30:21 +000068
69 for bl in breakpoint:
70 print 'breakpoint location load addr: %s' % hex(bl.GetLoadAddress())
71 print 'breakpoint location condition: %s' % hex(bl.GetCondition())
Johnny Chenf74cb502011-07-18 23:11:07 +000072
73and rich comparion methods which allow the API program to use,
74
75 if aBreakpoint == bBreakpoint:
76 ...
77
78to compare two breakpoints for equality."
79) SBBreakpoint;
Johnny Chen5de6a792011-07-18 21:30:21 +000080class SBBreakpoint
81{
82public:
83
84 typedef bool (*BreakpointHitCallback) (void *baton,
85 SBProcess &process,
86 SBThread &thread,
87 lldb::SBBreakpointLocation &location);
88
89 SBBreakpoint ();
90
91 SBBreakpoint (const lldb::SBBreakpoint& rhs);
92
93 ~SBBreakpoint();
94
95 break_id_t
96 GetID () const;
97
98 bool
99 IsValid() const;
100
101 void
102 ClearAllBreakpointSites ();
103
104 lldb::SBBreakpointLocation
105 FindLocationByAddress (lldb::addr_t vm_addr);
106
107 lldb::break_id_t
108 FindLocationIDByAddress (lldb::addr_t vm_addr);
109
110 lldb::SBBreakpointLocation
111 FindLocationByID (lldb::break_id_t bp_loc_id);
112
113 lldb::SBBreakpointLocation
114 GetLocationAtIndex (uint32_t index);
115
116 void
117 SetEnabled (bool enable);
118
119 bool
120 IsEnabled ();
Jim Ingham11c81082012-09-25 23:55:19 +0000121
Jim Inghamca36cd12012-10-05 19:16:31 +0000122 void
123 SetOneShot (bool one_shot);
124
125 bool
126 IsOneShot ();
127
Jim Ingham11c81082012-09-25 23:55:19 +0000128 bool
129 IsInternal ();
Johnny Chen5de6a792011-07-18 21:30:21 +0000130
131 uint32_t
132 GetHitCount () const;
133
134 void
135 SetIgnoreCount (uint32_t count);
136
137 uint32_t
138 GetIgnoreCount () const;
139
Johnny Chen85ced802011-10-18 19:13:06 +0000140 %feature("docstring", "
141 //--------------------------------------------------------------------------
142 /// The breakpoint stops only if the condition expression evaluates to true.
143 //--------------------------------------------------------------------------
144 ") SetCondition;
Johnny Chen5de6a792011-07-18 21:30:21 +0000145 void
146 SetCondition (const char *condition);
147
Johnny Chen85ced802011-10-18 19:13:06 +0000148 %feature("docstring", "
149 //------------------------------------------------------------------
150 /// Get the condition expression for the breakpoint.
151 //------------------------------------------------------------------
152 ") GetCondition;
Johnny Chen5de6a792011-07-18 21:30:21 +0000153 const char *
154 GetCondition ();
155
156 void
157 SetThreadID (lldb::tid_t sb_thread_id);
158
159 lldb::tid_t
160 GetThreadID ();
161
162 void
163 SetThreadIndex (uint32_t index);
164
165 uint32_t
166 GetThreadIndex() const;
167
168 void
169 SetThreadName (const char *thread_name);
170
171 const char *
172 GetThreadName () const;
173
174 void
175 SetQueueName (const char *queue_name);
176
177 const char *
178 GetQueueName () const;
179
Jim Inghamd80102e2014-04-02 01:04:55 +0000180 %feature("docstring", "
181 //------------------------------------------------------------------
182 /// Set the name of the script function to be called when the breakpoint is hit.
183 //------------------------------------------------------------------
184 ") SetScriptCallbackFunction;
Johnny Chen5de6a792011-07-18 21:30:21 +0000185 void
Jim Inghamd80102e2014-04-02 01:04:55 +0000186 SetScriptCallbackFunction (const char *callback_function_name);
Johnny Chen5de6a792011-07-18 21:30:21 +0000187
Jim Inghamd80102e2014-04-02 01:04:55 +0000188 %feature("docstring", "
189 //------------------------------------------------------------------
190 /// Provide the body for the script function to be called when the breakpoint is hit.
191 /// The body will be wrapped in a function, which be passed two arguments:
192 /// 'frame' - which holds the bottom-most SBFrame of the thread that hit the breakpoint
193 /// 'bpno' - which is the SBBreakpointLocation to which the callback was attached.
194 ///
195 /// The error parameter is currently ignored, but will at some point hold the Python
196 /// compilation diagnostics.
197 /// Returns true if the body compiles successfully, false if not.
198 //------------------------------------------------------------------
199 ") SetScriptCallbackBody;
200 SBError
201 SetScriptCallbackBody (const char *script_body_text);
202
Johnny Chen5de6a792011-07-18 21:30:21 +0000203 size_t
204 GetNumResolvedLocations() const;
205
206 size_t
207 GetNumLocations() const;
208
209 bool
210 GetDescription (lldb::SBStream &description);
211
Enrico Granatac3387332013-05-03 01:29:27 +0000212 bool
213 operator == (const lldb::SBBreakpoint& rhs);
214
215 bool
216 operator != (const lldb::SBBreakpoint& rhs);
217
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000218 static bool
219 EventIsBreakpointEvent (const lldb::SBEvent &event);
220
Johnny Chen5de6a792011-07-18 21:30:21 +0000221 static lldb::BreakpointEventType
222 GetBreakpointEventTypeFromEvent (const lldb::SBEvent& event);
223
224 static lldb::SBBreakpoint
225 GetBreakpointFromEvent (const lldb::SBEvent& event);
226
227 static lldb::SBBreakpointLocation
228 GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000229
230 static uint32_t
231 GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event_sp);
Enrico Granatac01dc4a2013-06-10 22:39:08 +0000232
233 %pythoncode %{
234
235 __swig_getmethods__["id"] = GetID
236 if _newclass: id = property(GetID, None, doc='''A read only property that returns the ID of this breakpoint.''')
237
238 __swig_getmethods__["enabled"] = IsEnabled
239 __swig_setmethods__["enabled"] = SetEnabled
240 if _newclass: enabled = property(IsEnabled, SetEnabled, doc='''A read/write property that configures whether this breakpoint is enabled or not.''')
241
242 __swig_getmethods__["one_shot"] = IsOneShot
243 __swig_setmethods__["one_shot"] = SetOneShot
244 if _newclass: one_shot = property(IsOneShot, SetOneShot, doc='''A read/write property that configures whether this breakpoint is one-shot (deleted when hit) or not.''')
245
246 __swig_getmethods__["num_locations"] = GetNumLocations
247 if _newclass: num_locations = property(GetNumLocations, None, doc='''A read only property that returns the count of locations of this breakpoint.''')
248
249 %}
250
251
Johnny Chen5de6a792011-07-18 21:30:21 +0000252};
253
254} // namespace lldb