py-breakpoint.c revision 1.7 1 1.1 christos /* Python interface to breakpoints
2 1.1 christos
3 1.7 christos Copyright (C) 2008-2017 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "defs.h"
21 1.1 christos #include "value.h"
22 1.1 christos #include "python-internal.h"
23 1.1 christos #include "python.h"
24 1.1 christos #include "charset.h"
25 1.1 christos #include "breakpoint.h"
26 1.1 christos #include "gdbcmd.h"
27 1.1 christos #include "gdbthread.h"
28 1.1 christos #include "observer.h"
29 1.1 christos #include "cli/cli-script.h"
30 1.1 christos #include "ada-lang.h"
31 1.1 christos #include "arch-utils.h"
32 1.1 christos #include "language.h"
33 1.6 christos #include "location.h"
34 1.6 christos #include "py-event.h"
35 1.1 christos
36 1.1 christos /* Number of live breakpoints. */
37 1.1 christos static int bppy_live;
38 1.1 christos
39 1.1 christos /* Variables used to pass information between the Breakpoint
40 1.1 christos constructor and the breakpoint-created hook function. */
41 1.1 christos gdbpy_breakpoint_object *bppy_pending_object;
42 1.1 christos
43 1.1 christos /* Function that is called when a Python condition is evaluated. */
44 1.7 christos static const char stop_func[] = "stop";
45 1.1 christos
46 1.1 christos /* This is used to initialize various gdb.bp_* constants. */
47 1.1 christos struct pybp_code
48 1.1 christos {
49 1.1 christos /* The name. */
50 1.1 christos const char *name;
51 1.1 christos /* The code. */
52 1.1 christos int code;
53 1.1 christos };
54 1.1 christos
55 1.1 christos /* Entries related to the type of user set breakpoints. */
56 1.1 christos static struct pybp_code pybp_codes[] =
57 1.1 christos {
58 1.1 christos { "BP_NONE", bp_none},
59 1.1 christos { "BP_BREAKPOINT", bp_breakpoint},
60 1.1 christos { "BP_WATCHPOINT", bp_watchpoint},
61 1.1 christos { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
62 1.1 christos { "BP_READ_WATCHPOINT", bp_read_watchpoint},
63 1.1 christos { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint},
64 1.1 christos {NULL} /* Sentinel. */
65 1.1 christos };
66 1.1 christos
67 1.1 christos /* Entries related to the type of watchpoint. */
68 1.1 christos static struct pybp_code pybp_watch_types[] =
69 1.1 christos {
70 1.1 christos { "WP_READ", hw_read},
71 1.1 christos { "WP_WRITE", hw_write},
72 1.1 christos { "WP_ACCESS", hw_access},
73 1.1 christos {NULL} /* Sentinel. */
74 1.1 christos };
75 1.1 christos
76 1.1 christos /* Python function which checks the validity of a breakpoint object. */
77 1.1 christos static PyObject *
78 1.1 christos bppy_is_valid (PyObject *self, PyObject *args)
79 1.1 christos {
80 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
81 1.1 christos
82 1.1 christos if (self_bp->bp)
83 1.1 christos Py_RETURN_TRUE;
84 1.1 christos Py_RETURN_FALSE;
85 1.1 christos }
86 1.1 christos
87 1.1 christos /* Python function to test whether or not the breakpoint is enabled. */
88 1.1 christos static PyObject *
89 1.1 christos bppy_get_enabled (PyObject *self, void *closure)
90 1.1 christos {
91 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
92 1.1 christos
93 1.1 christos BPPY_REQUIRE_VALID (self_bp);
94 1.1 christos if (! self_bp->bp)
95 1.1 christos Py_RETURN_FALSE;
96 1.1 christos if (self_bp->bp->enable_state == bp_enabled)
97 1.1 christos Py_RETURN_TRUE;
98 1.1 christos Py_RETURN_FALSE;
99 1.1 christos }
100 1.1 christos
101 1.1 christos /* Python function to test whether or not the breakpoint is silent. */
102 1.1 christos static PyObject *
103 1.1 christos bppy_get_silent (PyObject *self, void *closure)
104 1.1 christos {
105 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
106 1.1 christos
107 1.1 christos BPPY_REQUIRE_VALID (self_bp);
108 1.1 christos if (self_bp->bp->silent)
109 1.1 christos Py_RETURN_TRUE;
110 1.1 christos Py_RETURN_FALSE;
111 1.1 christos }
112 1.1 christos
113 1.1 christos /* Python function to set the enabled state of a breakpoint. */
114 1.1 christos static int
115 1.1 christos bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
116 1.1 christos {
117 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
118 1.1 christos int cmp;
119 1.1 christos
120 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
121 1.1 christos
122 1.1 christos if (newvalue == NULL)
123 1.1 christos {
124 1.1 christos PyErr_SetString (PyExc_TypeError,
125 1.1 christos _("Cannot delete `enabled' attribute."));
126 1.1 christos
127 1.1 christos return -1;
128 1.1 christos }
129 1.1 christos else if (! PyBool_Check (newvalue))
130 1.1 christos {
131 1.1 christos PyErr_SetString (PyExc_TypeError,
132 1.1 christos _("The value of `enabled' must be a boolean."));
133 1.1 christos return -1;
134 1.1 christos }
135 1.1 christos
136 1.1 christos cmp = PyObject_IsTrue (newvalue);
137 1.1 christos if (cmp < 0)
138 1.1 christos return -1;
139 1.1 christos
140 1.5 christos TRY
141 1.1 christos {
142 1.1 christos if (cmp == 1)
143 1.1 christos enable_breakpoint (self_bp->bp);
144 1.1 christos else
145 1.1 christos disable_breakpoint (self_bp->bp);
146 1.1 christos }
147 1.5 christos CATCH (except, RETURN_MASK_ALL)
148 1.5 christos {
149 1.5 christos GDB_PY_SET_HANDLE_EXCEPTION (except);
150 1.5 christos }
151 1.5 christos END_CATCH
152 1.1 christos
153 1.1 christos return 0;
154 1.1 christos }
155 1.1 christos
156 1.1 christos /* Python function to set the 'silent' state of a breakpoint. */
157 1.1 christos static int
158 1.1 christos bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
159 1.1 christos {
160 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
161 1.1 christos int cmp;
162 1.1 christos
163 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
164 1.1 christos
165 1.1 christos if (newvalue == NULL)
166 1.1 christos {
167 1.1 christos PyErr_SetString (PyExc_TypeError,
168 1.1 christos _("Cannot delete `silent' attribute."));
169 1.1 christos return -1;
170 1.1 christos }
171 1.1 christos else if (! PyBool_Check (newvalue))
172 1.1 christos {
173 1.1 christos PyErr_SetString (PyExc_TypeError,
174 1.1 christos _("The value of `silent' must be a boolean."));
175 1.1 christos return -1;
176 1.1 christos }
177 1.1 christos
178 1.1 christos cmp = PyObject_IsTrue (newvalue);
179 1.1 christos if (cmp < 0)
180 1.1 christos return -1;
181 1.1 christos else
182 1.1 christos breakpoint_set_silent (self_bp->bp, cmp);
183 1.1 christos
184 1.1 christos return 0;
185 1.1 christos }
186 1.1 christos
187 1.1 christos /* Python function to set the thread of a breakpoint. */
188 1.1 christos static int
189 1.1 christos bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
190 1.1 christos {
191 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
192 1.1 christos long id;
193 1.1 christos
194 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
195 1.1 christos
196 1.1 christos if (newvalue == NULL)
197 1.1 christos {
198 1.1 christos PyErr_SetString (PyExc_TypeError,
199 1.1 christos _("Cannot delete `thread' attribute."));
200 1.1 christos return -1;
201 1.1 christos }
202 1.1 christos else if (PyInt_Check (newvalue))
203 1.1 christos {
204 1.1 christos if (! gdb_py_int_as_long (newvalue, &id))
205 1.1 christos return -1;
206 1.1 christos
207 1.6 christos if (!valid_global_thread_id (id))
208 1.1 christos {
209 1.1 christos PyErr_SetString (PyExc_RuntimeError,
210 1.1 christos _("Invalid thread ID."));
211 1.1 christos return -1;
212 1.1 christos }
213 1.1 christos }
214 1.1 christos else if (newvalue == Py_None)
215 1.1 christos id = -1;
216 1.1 christos else
217 1.1 christos {
218 1.1 christos PyErr_SetString (PyExc_TypeError,
219 1.1 christos _("The value of `thread' must be an integer or None."));
220 1.1 christos return -1;
221 1.1 christos }
222 1.1 christos
223 1.1 christos breakpoint_set_thread (self_bp->bp, id);
224 1.1 christos
225 1.1 christos return 0;
226 1.1 christos }
227 1.1 christos
228 1.1 christos /* Python function to set the (Ada) task of a breakpoint. */
229 1.1 christos static int
230 1.1 christos bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
231 1.1 christos {
232 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
233 1.1 christos long id;
234 1.1 christos int valid_id = 0;
235 1.1 christos
236 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
237 1.1 christos
238 1.1 christos if (newvalue == NULL)
239 1.1 christos {
240 1.1 christos PyErr_SetString (PyExc_TypeError,
241 1.1 christos _("Cannot delete `task' attribute."));
242 1.1 christos return -1;
243 1.1 christos }
244 1.1 christos else if (PyInt_Check (newvalue))
245 1.1 christos {
246 1.1 christos if (! gdb_py_int_as_long (newvalue, &id))
247 1.1 christos return -1;
248 1.1 christos
249 1.5 christos TRY
250 1.1 christos {
251 1.1 christos valid_id = valid_task_id (id);
252 1.1 christos }
253 1.5 christos CATCH (except, RETURN_MASK_ALL)
254 1.5 christos {
255 1.5 christos GDB_PY_SET_HANDLE_EXCEPTION (except);
256 1.5 christos }
257 1.5 christos END_CATCH
258 1.1 christos
259 1.1 christos if (! valid_id)
260 1.1 christos {
261 1.1 christos PyErr_SetString (PyExc_RuntimeError,
262 1.1 christos _("Invalid task ID."));
263 1.1 christos return -1;
264 1.1 christos }
265 1.1 christos }
266 1.1 christos else if (newvalue == Py_None)
267 1.1 christos id = 0;
268 1.1 christos else
269 1.1 christos {
270 1.1 christos PyErr_SetString (PyExc_TypeError,
271 1.1 christos _("The value of `task' must be an integer or None."));
272 1.1 christos return -1;
273 1.1 christos }
274 1.1 christos
275 1.1 christos breakpoint_set_task (self_bp->bp, id);
276 1.1 christos
277 1.1 christos return 0;
278 1.1 christos }
279 1.1 christos
280 1.1 christos /* Python function which deletes the underlying GDB breakpoint. This
281 1.1 christos triggers the breakpoint_deleted observer which will call
282 1.1 christos gdbpy_breakpoint_deleted; that function cleans up the Python
283 1.1 christos sections. */
284 1.1 christos
285 1.1 christos static PyObject *
286 1.1 christos bppy_delete_breakpoint (PyObject *self, PyObject *args)
287 1.1 christos {
288 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
289 1.1 christos
290 1.1 christos BPPY_REQUIRE_VALID (self_bp);
291 1.1 christos
292 1.5 christos TRY
293 1.1 christos {
294 1.1 christos delete_breakpoint (self_bp->bp);
295 1.1 christos }
296 1.5 christos CATCH (except, RETURN_MASK_ALL)
297 1.5 christos {
298 1.5 christos GDB_PY_HANDLE_EXCEPTION (except);
299 1.5 christos }
300 1.5 christos END_CATCH
301 1.1 christos
302 1.1 christos Py_RETURN_NONE;
303 1.1 christos }
304 1.1 christos
305 1.1 christos
306 1.1 christos /* Python function to set the ignore count of a breakpoint. */
307 1.1 christos static int
308 1.1 christos bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
309 1.1 christos {
310 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
311 1.1 christos long value;
312 1.1 christos
313 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
314 1.1 christos
315 1.1 christos if (newvalue == NULL)
316 1.1 christos {
317 1.1 christos PyErr_SetString (PyExc_TypeError,
318 1.1 christos _("Cannot delete `ignore_count' attribute."));
319 1.1 christos return -1;
320 1.1 christos }
321 1.1 christos else if (! PyInt_Check (newvalue))
322 1.1 christos {
323 1.1 christos PyErr_SetString (PyExc_TypeError,
324 1.1 christos _("The value of `ignore_count' must be an integer."));
325 1.1 christos return -1;
326 1.1 christos }
327 1.1 christos
328 1.1 christos if (! gdb_py_int_as_long (newvalue, &value))
329 1.1 christos return -1;
330 1.1 christos
331 1.1 christos if (value < 0)
332 1.1 christos value = 0;
333 1.1 christos
334 1.5 christos TRY
335 1.1 christos {
336 1.1 christos set_ignore_count (self_bp->number, (int) value, 0);
337 1.1 christos }
338 1.5 christos CATCH (except, RETURN_MASK_ALL)
339 1.5 christos {
340 1.5 christos GDB_PY_SET_HANDLE_EXCEPTION (except);
341 1.5 christos }
342 1.5 christos END_CATCH
343 1.1 christos
344 1.1 christos return 0;
345 1.1 christos }
346 1.1 christos
347 1.1 christos /* Python function to set the hit count of a breakpoint. */
348 1.1 christos static int
349 1.1 christos bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
350 1.1 christos {
351 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
352 1.1 christos
353 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
354 1.1 christos
355 1.1 christos if (newvalue == NULL)
356 1.1 christos {
357 1.1 christos PyErr_SetString (PyExc_TypeError,
358 1.1 christos _("Cannot delete `hit_count' attribute."));
359 1.1 christos return -1;
360 1.1 christos }
361 1.1 christos else
362 1.1 christos {
363 1.1 christos long value;
364 1.1 christos
365 1.1 christos if (! gdb_py_int_as_long (newvalue, &value))
366 1.1 christos return -1;
367 1.1 christos
368 1.1 christos if (value != 0)
369 1.1 christos {
370 1.1 christos PyErr_SetString (PyExc_AttributeError,
371 1.1 christos _("The value of `hit_count' must be zero."));
372 1.1 christos return -1;
373 1.1 christos }
374 1.1 christos }
375 1.1 christos
376 1.1 christos self_bp->bp->hit_count = 0;
377 1.1 christos
378 1.1 christos return 0;
379 1.1 christos }
380 1.1 christos
381 1.1 christos /* Python function to get the location of a breakpoint. */
382 1.1 christos static PyObject *
383 1.1 christos bppy_get_location (PyObject *self, void *closure)
384 1.1 christos {
385 1.6 christos const char *str;
386 1.1 christos gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
387 1.1 christos
388 1.1 christos BPPY_REQUIRE_VALID (obj);
389 1.1 christos
390 1.1 christos if (obj->bp->type != bp_breakpoint)
391 1.1 christos Py_RETURN_NONE;
392 1.1 christos
393 1.7 christos str = event_location_to_string (obj->bp->location.get ());
394 1.1 christos if (! str)
395 1.1 christos str = "";
396 1.6 christos return host_string_to_python_string (str);
397 1.1 christos }
398 1.1 christos
399 1.1 christos /* Python function to get the breakpoint expression. */
400 1.1 christos static PyObject *
401 1.1 christos bppy_get_expression (PyObject *self, void *closure)
402 1.1 christos {
403 1.7 christos const char *str;
404 1.1 christos gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
405 1.1 christos struct watchpoint *wp;
406 1.1 christos
407 1.1 christos BPPY_REQUIRE_VALID (obj);
408 1.1 christos
409 1.1 christos if (!is_watchpoint (obj->bp))
410 1.1 christos Py_RETURN_NONE;
411 1.1 christos
412 1.1 christos wp = (struct watchpoint *) obj->bp;
413 1.1 christos
414 1.1 christos str = wp->exp_string;
415 1.1 christos if (! str)
416 1.1 christos str = "";
417 1.1 christos
418 1.6 christos return host_string_to_python_string (str);
419 1.1 christos }
420 1.1 christos
421 1.1 christos /* Python function to get the condition expression of a breakpoint. */
422 1.1 christos static PyObject *
423 1.1 christos bppy_get_condition (PyObject *self, void *closure)
424 1.1 christos {
425 1.1 christos char *str;
426 1.1 christos gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
427 1.1 christos
428 1.1 christos BPPY_REQUIRE_VALID (obj);
429 1.1 christos
430 1.1 christos str = obj->bp->cond_string;
431 1.1 christos if (! str)
432 1.1 christos Py_RETURN_NONE;
433 1.1 christos
434 1.6 christos return host_string_to_python_string (str);
435 1.1 christos }
436 1.1 christos
437 1.1 christos /* Returns 0 on success. Returns -1 on error, with a python exception set.
438 1.1 christos */
439 1.1 christos
440 1.1 christos static int
441 1.1 christos bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
442 1.1 christos {
443 1.7 christos gdb::unique_xmalloc_ptr<char> exp_holder;
444 1.7 christos const char *exp = NULL;
445 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
446 1.5 christos struct gdb_exception except = exception_none;
447 1.1 christos
448 1.1 christos BPPY_SET_REQUIRE_VALID (self_bp);
449 1.1 christos
450 1.1 christos if (newvalue == NULL)
451 1.1 christos {
452 1.1 christos PyErr_SetString (PyExc_TypeError,
453 1.1 christos _("Cannot delete `condition' attribute."));
454 1.1 christos return -1;
455 1.1 christos }
456 1.1 christos else if (newvalue == Py_None)
457 1.1 christos exp = "";
458 1.1 christos else
459 1.1 christos {
460 1.7 christos exp_holder = python_string_to_host_string (newvalue);
461 1.7 christos if (exp_holder == NULL)
462 1.1 christos return -1;
463 1.7 christos exp = exp_holder.get ();
464 1.1 christos }
465 1.1 christos
466 1.5 christos TRY
467 1.1 christos {
468 1.1 christos set_breakpoint_condition (self_bp->bp, exp, 0);
469 1.1 christos }
470 1.5 christos CATCH (ex, RETURN_MASK_ALL)
471 1.5 christos {
472 1.5 christos except = ex;
473 1.5 christos }
474 1.5 christos END_CATCH
475 1.1 christos
476 1.1 christos GDB_PY_SET_HANDLE_EXCEPTION (except);
477 1.1 christos
478 1.1 christos return 0;
479 1.1 christos }
480 1.1 christos
481 1.1 christos /* Python function to get the commands attached to a breakpoint. */
482 1.1 christos static PyObject *
483 1.1 christos bppy_get_commands (PyObject *self, void *closure)
484 1.1 christos {
485 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
486 1.1 christos struct breakpoint *bp = self_bp->bp;
487 1.1 christos long length;
488 1.1 christos PyObject *result;
489 1.1 christos
490 1.1 christos BPPY_REQUIRE_VALID (self_bp);
491 1.1 christos
492 1.1 christos if (! self_bp->bp->commands)
493 1.1 christos Py_RETURN_NONE;
494 1.1 christos
495 1.7 christos string_file stb;
496 1.1 christos
497 1.7 christos current_uiout->redirect (&stb);
498 1.5 christos TRY
499 1.1 christos {
500 1.1 christos print_command_lines (current_uiout, breakpoint_commands (bp), 0);
501 1.1 christos }
502 1.5 christos CATCH (except, RETURN_MASK_ALL)
503 1.1 christos {
504 1.7 christos current_uiout->redirect (NULL);
505 1.1 christos gdbpy_convert_exception (except);
506 1.1 christos return NULL;
507 1.1 christos }
508 1.5 christos END_CATCH
509 1.1 christos
510 1.7 christos current_uiout->redirect (NULL);
511 1.7 christos return host_string_to_python_string (stb.c_str ());
512 1.1 christos }
513 1.1 christos
514 1.1 christos /* Python function to get the breakpoint type. */
515 1.1 christos static PyObject *
516 1.1 christos bppy_get_type (PyObject *self, void *closure)
517 1.1 christos {
518 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
519 1.1 christos
520 1.1 christos BPPY_REQUIRE_VALID (self_bp);
521 1.1 christos
522 1.1 christos return PyInt_FromLong (self_bp->bp->type);
523 1.1 christos }
524 1.1 christos
525 1.1 christos /* Python function to get the visibility of the breakpoint. */
526 1.1 christos
527 1.1 christos static PyObject *
528 1.1 christos bppy_get_visibility (PyObject *self, void *closure)
529 1.1 christos {
530 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
531 1.1 christos
532 1.1 christos BPPY_REQUIRE_VALID (self_bp);
533 1.1 christos
534 1.6 christos if (user_breakpoint_p (self_bp->bp))
535 1.6 christos Py_RETURN_TRUE;
536 1.1 christos
537 1.6 christos Py_RETURN_FALSE;
538 1.1 christos }
539 1.1 christos
540 1.1 christos /* Python function to determine if the breakpoint is a temporary
541 1.1 christos breakpoint. */
542 1.1 christos
543 1.1 christos static PyObject *
544 1.1 christos bppy_get_temporary (PyObject *self, void *closure)
545 1.1 christos {
546 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
547 1.1 christos
548 1.1 christos BPPY_REQUIRE_VALID (self_bp);
549 1.1 christos
550 1.1 christos if (self_bp->bp->disposition == disp_del
551 1.1 christos || self_bp->bp->disposition == disp_del_at_next_stop)
552 1.1 christos Py_RETURN_TRUE;
553 1.1 christos
554 1.1 christos Py_RETURN_FALSE;
555 1.1 christos }
556 1.1 christos
557 1.6 christos /* Python function to determine if the breakpoint is a pending
558 1.6 christos breakpoint. */
559 1.6 christos
560 1.6 christos static PyObject *
561 1.6 christos bppy_get_pending (PyObject *self, void *closure)
562 1.6 christos {
563 1.6 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
564 1.6 christos
565 1.6 christos BPPY_REQUIRE_VALID (self_bp);
566 1.6 christos
567 1.6 christos if (is_watchpoint (self_bp->bp))
568 1.6 christos Py_RETURN_FALSE;
569 1.6 christos if (pending_breakpoint_p (self_bp->bp))
570 1.6 christos Py_RETURN_TRUE;
571 1.6 christos
572 1.6 christos Py_RETURN_FALSE;
573 1.6 christos }
574 1.6 christos
575 1.1 christos /* Python function to get the breakpoint's number. */
576 1.1 christos static PyObject *
577 1.1 christos bppy_get_number (PyObject *self, void *closure)
578 1.1 christos {
579 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
580 1.1 christos
581 1.1 christos BPPY_REQUIRE_VALID (self_bp);
582 1.1 christos
583 1.1 christos return PyInt_FromLong (self_bp->number);
584 1.1 christos }
585 1.1 christos
586 1.1 christos /* Python function to get the breakpoint's thread ID. */
587 1.1 christos static PyObject *
588 1.1 christos bppy_get_thread (PyObject *self, void *closure)
589 1.1 christos {
590 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
591 1.1 christos
592 1.1 christos BPPY_REQUIRE_VALID (self_bp);
593 1.1 christos
594 1.1 christos if (self_bp->bp->thread == -1)
595 1.1 christos Py_RETURN_NONE;
596 1.1 christos
597 1.1 christos return PyInt_FromLong (self_bp->bp->thread);
598 1.1 christos }
599 1.1 christos
600 1.1 christos /* Python function to get the breakpoint's task ID (in Ada). */
601 1.1 christos static PyObject *
602 1.1 christos bppy_get_task (PyObject *self, void *closure)
603 1.1 christos {
604 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
605 1.1 christos
606 1.1 christos BPPY_REQUIRE_VALID (self_bp);
607 1.1 christos
608 1.1 christos if (self_bp->bp->task == 0)
609 1.1 christos Py_RETURN_NONE;
610 1.1 christos
611 1.1 christos return PyInt_FromLong (self_bp->bp->task);
612 1.1 christos }
613 1.1 christos
614 1.1 christos /* Python function to get the breakpoint's hit count. */
615 1.1 christos static PyObject *
616 1.1 christos bppy_get_hit_count (PyObject *self, void *closure)
617 1.1 christos {
618 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
619 1.1 christos
620 1.1 christos BPPY_REQUIRE_VALID (self_bp);
621 1.1 christos
622 1.1 christos return PyInt_FromLong (self_bp->bp->hit_count);
623 1.1 christos }
624 1.1 christos
625 1.1 christos /* Python function to get the breakpoint's ignore count. */
626 1.1 christos static PyObject *
627 1.1 christos bppy_get_ignore_count (PyObject *self, void *closure)
628 1.1 christos {
629 1.1 christos gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
630 1.1 christos
631 1.1 christos BPPY_REQUIRE_VALID (self_bp);
632 1.1 christos
633 1.1 christos return PyInt_FromLong (self_bp->bp->ignore_count);
634 1.1 christos }
635 1.1 christos
636 1.1 christos /* Python function to create a new breakpoint. */
637 1.1 christos static int
638 1.1 christos bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
639 1.1 christos {
640 1.7 christos static const char *keywords[] = { "spec", "type", "wp_class", "internal",
641 1.7 christos "temporary", NULL };
642 1.1 christos const char *spec;
643 1.1 christos int type = bp_breakpoint;
644 1.1 christos int access_type = hw_write;
645 1.1 christos PyObject *internal = NULL;
646 1.1 christos PyObject *temporary = NULL;
647 1.1 christos int internal_bp = 0;
648 1.1 christos int temporary_bp = 0;
649 1.1 christos
650 1.7 christos if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
651 1.7 christos &spec, &type, &access_type,
652 1.7 christos &internal, &temporary))
653 1.1 christos return -1;
654 1.1 christos
655 1.1 christos if (internal)
656 1.1 christos {
657 1.1 christos internal_bp = PyObject_IsTrue (internal);
658 1.1 christos if (internal_bp == -1)
659 1.1 christos return -1;
660 1.1 christos }
661 1.1 christos
662 1.1 christos if (temporary != NULL)
663 1.1 christos {
664 1.1 christos temporary_bp = PyObject_IsTrue (temporary);
665 1.1 christos if (temporary_bp == -1)
666 1.1 christos return -1;
667 1.1 christos }
668 1.1 christos
669 1.1 christos bppy_pending_object = (gdbpy_breakpoint_object *) self;
670 1.1 christos bppy_pending_object->number = -1;
671 1.1 christos bppy_pending_object->bp = NULL;
672 1.1 christos
673 1.5 christos TRY
674 1.1 christos {
675 1.7 christos gdb::unique_xmalloc_ptr<char>
676 1.7 christos copy_holder (xstrdup (skip_spaces_const (spec)));
677 1.7 christos char *copy = copy_holder.get ();
678 1.1 christos
679 1.1 christos switch (type)
680 1.1 christos {
681 1.1 christos case bp_breakpoint:
682 1.1 christos {
683 1.7 christos event_location_up location
684 1.6 christos = string_to_event_location_basic (©, current_language);
685 1.1 christos create_breakpoint (python_gdbarch,
686 1.7 christos location.get (), NULL, -1, NULL,
687 1.1 christos 0,
688 1.1 christos temporary_bp, bp_breakpoint,
689 1.1 christos 0,
690 1.1 christos AUTO_BOOLEAN_TRUE,
691 1.1 christos &bkpt_breakpoint_ops,
692 1.1 christos 0, 1, internal_bp, 0);
693 1.1 christos break;
694 1.1 christos }
695 1.1 christos case bp_watchpoint:
696 1.1 christos {
697 1.1 christos if (access_type == hw_write)
698 1.1 christos watch_command_wrapper (copy, 0, internal_bp);
699 1.1 christos else if (access_type == hw_access)
700 1.1 christos awatch_command_wrapper (copy, 0, internal_bp);
701 1.1 christos else if (access_type == hw_read)
702 1.1 christos rwatch_command_wrapper (copy, 0, internal_bp);
703 1.1 christos else
704 1.1 christos error(_("Cannot understand watchpoint access type."));
705 1.1 christos break;
706 1.1 christos }
707 1.1 christos default:
708 1.1 christos error(_("Do not understand breakpoint type to set."));
709 1.1 christos }
710 1.1 christos }
711 1.5 christos CATCH (except, RETURN_MASK_ALL)
712 1.1 christos {
713 1.6 christos bppy_pending_object = NULL;
714 1.1 christos PyErr_Format (except.reason == RETURN_QUIT
715 1.1 christos ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
716 1.1 christos "%s", except.message);
717 1.1 christos return -1;
718 1.1 christos }
719 1.5 christos END_CATCH
720 1.1 christos
721 1.1 christos BPPY_SET_REQUIRE_VALID ((gdbpy_breakpoint_object *) self);
722 1.1 christos return 0;
723 1.1 christos }
724 1.1 christos
725 1.1 christos
726 1.1 christos
728 1.1 christos static int
729 1.1 christos build_bp_list (struct breakpoint *b, void *arg)
730 1.6 christos {
731 1.1 christos PyObject *list = (PyObject *) arg;
732 1.1 christos PyObject *bp = (PyObject *) b->py_bp_object;
733 1.1 christos int iserr = 0;
734 1.1 christos
735 1.1 christos /* Not all breakpoints will have a companion Python object.
736 1.1 christos Only breakpoints that were created via bppy_new, or
737 1.1 christos breakpoints that were created externally and are tracked by
738 1.1 christos the Python Scripting API. */
739 1.1 christos if (bp)
740 1.1 christos iserr = PyList_Append (list, bp);
741 1.1 christos
742 1.1 christos if (iserr == -1)
743 1.1 christos return 1;
744 1.1 christos
745 1.1 christos return 0;
746 1.1 christos }
747 1.1 christos
748 1.1 christos /* Static function to return a tuple holding all breakpoints. */
749 1.1 christos
750 1.1 christos PyObject *
751 1.1 christos gdbpy_breakpoints (PyObject *self, PyObject *args)
752 1.1 christos {
753 1.6 christos if (bppy_live == 0)
754 1.1 christos return PyTuple_New (0);
755 1.7 christos
756 1.7 christos gdbpy_ref<> list (PyList_New (0));
757 1.1 christos if (list == NULL)
758 1.1 christos return NULL;
759 1.6 christos
760 1.1 christos /* If iterate_over_breakpoints returns non NULL it signals an error
761 1.1 christos condition. In that case abandon building the list and return
762 1.7 christos NULL. */
763 1.7 christos if (iterate_over_breakpoints (build_bp_list, list.get ()) != NULL)
764 1.1 christos return NULL;
765 1.7 christos
766 1.1 christos return PyList_AsTuple (list.get ());
767 1.1 christos }
768 1.1 christos
769 1.1 christos /* Call the "stop" method (if implemented) in the breakpoint
770 1.1 christos class. If the method returns True, the inferior will be
771 1.1 christos stopped at the breakpoint. Otherwise the inferior will be
772 1.1 christos allowed to continue. */
773 1.3 christos
774 1.3 christos enum ext_lang_bp_stop
775 1.3 christos gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
776 1.1 christos struct breakpoint *b)
777 1.3 christos {
778 1.3 christos int stop;
779 1.3 christos struct gdbpy_breakpoint_object *bp_obj = b->py_bp_object;
780 1.3 christos PyObject *py_bp = (PyObject *) bp_obj;
781 1.1 christos struct gdbarch *garch;
782 1.3 christos
783 1.3 christos if (bp_obj == NULL)
784 1.3 christos return EXT_LANG_BP_STOP_UNSET;
785 1.3 christos
786 1.3 christos stop = -1;
787 1.7 christos garch = b->gdbarch ? b->gdbarch : get_current_arch ();
788 1.7 christos
789 1.1 christos gdbpy_enter enter_py (garch, current_language);
790 1.1 christos
791 1.1 christos if (bp_obj->is_finish_bp)
792 1.1 christos bpfinishpy_pre_stop_hook (bp_obj);
793 1.1 christos
794 1.1 christos if (PyObject_HasAttrString (py_bp, stop_func))
795 1.7 christos {
796 1.1 christos gdbpy_ref<> result (PyObject_CallMethod (py_bp, stop_func, NULL));
797 1.3 christos
798 1.7 christos stop = 1;
799 1.1 christos if (result != NULL)
800 1.7 christos {
801 1.1 christos int evaluate = PyObject_IsTrue (result.get ());
802 1.1 christos
803 1.1 christos if (evaluate == -1)
804 1.1 christos gdbpy_print_stack ();
805 1.1 christos
806 1.1 christos /* If the "stop" function returns False that means
807 1.1 christos the Python breakpoint wants GDB to continue. */
808 1.1 christos if (! evaluate)
809 1.1 christos stop = 0;
810 1.1 christos }
811 1.1 christos else
812 1.1 christos gdbpy_print_stack ();
813 1.1 christos }
814 1.1 christos
815 1.1 christos if (bp_obj->is_finish_bp)
816 1.1 christos bpfinishpy_post_stop_hook (bp_obj);
817 1.3 christos
818 1.3 christos if (stop < 0)
819 1.3 christos return EXT_LANG_BP_STOP_UNSET;
820 1.1 christos return stop ? EXT_LANG_BP_STOP_YES : EXT_LANG_BP_STOP_NO;
821 1.1 christos }
822 1.1 christos
823 1.1 christos /* Checks if the "stop" method exists in this breakpoint.
824 1.1 christos Used by condition_command to ensure mutual exclusion of breakpoint
825 1.1 christos conditions. */
826 1.1 christos
827 1.3 christos int
828 1.3 christos gdbpy_breakpoint_has_cond (const struct extension_language_defn *extlang,
829 1.1 christos struct breakpoint *b)
830 1.3 christos {
831 1.3 christos PyObject *py_bp;
832 1.3 christos struct gdbarch *garch;
833 1.3 christos
834 1.3 christos if (b->py_bp_object == NULL)
835 1.3 christos return 0;
836 1.3 christos
837 1.3 christos py_bp = (PyObject *) b->py_bp_object;
838 1.1 christos garch = b->gdbarch ? b->gdbarch : get_current_arch ();
839 1.7 christos
840 1.7 christos gdbpy_enter enter_py (garch, current_language);
841 1.1 christos return PyObject_HasAttrString (py_bp, stop_func);
842 1.1 christos }
843 1.1 christos
844 1.1 christos
845 1.1 christos
847 1.1 christos /* Event callback functions. */
848 1.1 christos
849 1.1 christos /* Callback that is used when a breakpoint is created. This function
850 1.1 christos will create a new Python breakpoint object. */
851 1.1 christos static void
852 1.1 christos gdbpy_breakpoint_created (struct breakpoint *bp)
853 1.1 christos {
854 1.1 christos gdbpy_breakpoint_object *newbp;
855 1.6 christos PyGILState_STATE state;
856 1.1 christos
857 1.1 christos if (!user_breakpoint_p (bp) && bppy_pending_object == NULL)
858 1.1 christos return;
859 1.1 christos
860 1.1 christos if (bp->type != bp_breakpoint
861 1.1 christos && bp->type != bp_watchpoint
862 1.1 christos && bp->type != bp_hardware_watchpoint
863 1.1 christos && bp->type != bp_read_watchpoint
864 1.1 christos && bp->type != bp_access_watchpoint)
865 1.1 christos return;
866 1.1 christos
867 1.1 christos state = PyGILState_Ensure ();
868 1.1 christos
869 1.1 christos if (bppy_pending_object)
870 1.1 christos {
871 1.1 christos newbp = bppy_pending_object;
872 1.1 christos bppy_pending_object = NULL;
873 1.1 christos }
874 1.1 christos else
875 1.1 christos newbp = PyObject_New (gdbpy_breakpoint_object, &breakpoint_object_type);
876 1.1 christos if (newbp)
877 1.1 christos {
878 1.1 christos newbp->number = bp->number;
879 1.1 christos newbp->bp = bp;
880 1.1 christos newbp->bp->py_bp_object = newbp;
881 1.1 christos newbp->is_finish_bp = 0;
882 1.1 christos Py_INCREF (newbp);
883 1.1 christos ++bppy_live;
884 1.1 christos }
885 1.1 christos else
886 1.1 christos {
887 1.1 christos PyErr_SetString (PyExc_RuntimeError,
888 1.1 christos _("Error while creating breakpoint from GDB."));
889 1.1 christos gdbpy_print_stack ();
890 1.6 christos }
891 1.6 christos
892 1.6 christos if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_created))
893 1.6 christos {
894 1.6 christos if (evpy_emit_event ((PyObject *) newbp,
895 1.6 christos gdb_py_events.breakpoint_created) < 0)
896 1.6 christos gdbpy_print_stack ();
897 1.1 christos }
898 1.1 christos
899 1.1 christos PyGILState_Release (state);
900 1.1 christos }
901 1.1 christos
902 1.1 christos /* Callback that is used when a breakpoint is deleted. This will
903 1.1 christos invalidate the corresponding Python object. */
904 1.1 christos static void
905 1.1 christos gdbpy_breakpoint_deleted (struct breakpoint *b)
906 1.1 christos {
907 1.1 christos int num = b->number;
908 1.1 christos PyGILState_STATE state;
909 1.1 christos struct breakpoint *bp = NULL;
910 1.1 christos
911 1.1 christos state = PyGILState_Ensure ();
912 1.1 christos bp = get_breakpoint (num);
913 1.7 christos if (bp)
914 1.7 christos {
915 1.1 christos gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
916 1.6 christos if (bp_obj != NULL)
917 1.6 christos {
918 1.7 christos if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_deleted))
919 1.6 christos {
920 1.6 christos if (evpy_emit_event ((PyObject *) bp_obj.get (),
921 1.6 christos gdb_py_events.breakpoint_deleted) < 0)
922 1.6 christos gdbpy_print_stack ();
923 1.1 christos }
924 1.1 christos
925 1.1 christos bp_obj->bp = NULL;
926 1.1 christos --bppy_live;
927 1.1 christos }
928 1.1 christos }
929 1.1 christos PyGILState_Release (state);
930 1.6 christos }
931 1.6 christos
932 1.6 christos /* Callback that is used when a breakpoint is modified. */
933 1.6 christos
934 1.6 christos static void
935 1.6 christos gdbpy_breakpoint_modified (struct breakpoint *b)
936 1.6 christos {
937 1.6 christos int num = b->number;
938 1.6 christos PyGILState_STATE state;
939 1.6 christos struct breakpoint *bp = NULL;
940 1.6 christos gdbpy_breakpoint_object *bp_obj;
941 1.6 christos
942 1.6 christos state = PyGILState_Ensure ();
943 1.6 christos bp = get_breakpoint (num);
944 1.6 christos if (bp)
945 1.6 christos {
946 1.6 christos PyObject *bp_obj = (PyObject *) bp->py_bp_object;
947 1.6 christos if (bp_obj)
948 1.6 christos {
949 1.6 christos if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_modified))
950 1.6 christos {
951 1.6 christos if (evpy_emit_event (bp_obj,
952 1.6 christos gdb_py_events.breakpoint_modified) < 0)
953 1.6 christos gdbpy_print_stack ();
954 1.6 christos }
955 1.6 christos }
956 1.6 christos }
957 1.6 christos PyGILState_Release (state);
958 1.1 christos }
959 1.1 christos
960 1.1 christos
961 1.1 christos
963 1.1 christos /* Initialize the Python breakpoint code. */
964 1.1 christos int
965 1.1 christos gdbpy_initialize_breakpoints (void)
966 1.1 christos {
967 1.1 christos int i;
968 1.1 christos
969 1.1 christos breakpoint_object_type.tp_new = PyType_GenericNew;
970 1.1 christos if (PyType_Ready (&breakpoint_object_type) < 0)
971 1.1 christos return -1;
972 1.1 christos
973 1.1 christos if (gdb_pymodule_addobject (gdb_module, "Breakpoint",
974 1.1 christos (PyObject *) &breakpoint_object_type) < 0)
975 1.1 christos return -1;
976 1.6 christos
977 1.1 christos observer_attach_breakpoint_created (gdbpy_breakpoint_created);
978 1.1 christos observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
979 1.1 christos observer_attach_breakpoint_modified (gdbpy_breakpoint_modified);
980 1.1 christos
981 1.1 christos /* Add breakpoint types constants. */
982 1.1 christos for (i = 0; pybp_codes[i].name; ++i)
983 1.1 christos {
984 1.1 christos if (PyModule_AddIntConstant (gdb_module,
985 1.1 christos /* Cast needed for Python 2.4. */
986 1.1 christos (char *) pybp_codes[i].name,
987 1.1 christos pybp_codes[i].code) < 0)
988 1.1 christos return -1;
989 1.1 christos }
990 1.1 christos
991 1.1 christos /* Add watchpoint types constants. */
992 1.1 christos for (i = 0; pybp_watch_types[i].name; ++i)
993 1.1 christos {
994 1.1 christos if (PyModule_AddIntConstant (gdb_module,
995 1.1 christos /* Cast needed for Python 2.4. */
996 1.1 christos (char *) pybp_watch_types[i].name,
997 1.1 christos pybp_watch_types[i].code) < 0)
998 1.1 christos return -1;
999 1.1 christos }
1000 1.1 christos
1001 1.1 christos return 0;
1002 1.1 christos }
1003 1.1 christos
1004 1.1 christos
1005 1.1 christos
1007 1.1 christos /* Helper function that overrides this Python object's
1008 1.1 christos PyObject_GenericSetAttr to allow extra validation of the attribute
1009 1.1 christos being set. */
1010 1.1 christos
1011 1.7 christos static int
1012 1.1 christos local_setattro (PyObject *self, PyObject *name, PyObject *v)
1013 1.1 christos {
1014 1.1 christos gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
1015 1.1 christos gdb::unique_xmalloc_ptr<char> attr (python_string_to_host_string (name));
1016 1.1 christos
1017 1.3 christos if (attr == NULL)
1018 1.3 christos return -1;
1019 1.7 christos
1020 1.3 christos /* If the attribute trying to be set is the "stop" method,
1021 1.3 christos but we already have a condition set in the CLI or other extension
1022 1.3 christos language, disallow this operation. */
1023 1.3 christos if (strcmp (attr.get (), stop_func) == 0)
1024 1.3 christos {
1025 1.3 christos const struct extension_language_defn *extlang = NULL;
1026 1.3 christos
1027 1.3 christos if (obj->bp->cond_string != NULL)
1028 1.3 christos extlang = get_ext_lang_defn (EXT_LANG_GDB);
1029 1.3 christos if (extlang == NULL)
1030 1.3 christos extlang = get_breakpoint_cond_ext_lang (obj->bp, EXT_LANG_PYTHON);
1031 1.3 christos if (extlang != NULL)
1032 1.3 christos {
1033 1.3 christos char *error_text;
1034 1.3 christos
1035 1.3 christos error_text
1036 1.3 christos = xstrprintf (_("Only one stop condition allowed. There is"
1037 1.3 christos " currently a %s stop condition defined for"
1038 1.3 christos " this breakpoint."),
1039 1.3 christos ext_lang_capitalized_name (extlang));
1040 1.1 christos PyErr_SetString (PyExc_RuntimeError, error_text);
1041 1.1 christos xfree (error_text);
1042 1.1 christos return -1;
1043 1.1 christos }
1044 1.1 christos }
1045 1.7 christos
1046 1.1 christos return PyObject_GenericSetAttr ((PyObject *)self, name, v);
1047 1.1 christos }
1048 1.1 christos
1049 1.1 christos static gdb_PyGetSetDef breakpoint_object_getset[] = {
1050 1.1 christos { "enabled", bppy_get_enabled, bppy_set_enabled,
1051 1.1 christos "Boolean telling whether the breakpoint is enabled.", NULL },
1052 1.1 christos { "silent", bppy_get_silent, bppy_set_silent,
1053 1.1 christos "Boolean telling whether the breakpoint is silent.", NULL },
1054 1.1 christos { "thread", bppy_get_thread, bppy_set_thread,
1055 1.1 christos "Thread ID for the breakpoint.\n\
1056 1.1 christos If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
1057 1.1 christos If the value is None, then this breakpoint is not thread-specific.\n\
1058 1.1 christos No other type of value can be used.", NULL },
1059 1.1 christos { "task", bppy_get_task, bppy_set_task,
1060 1.1 christos "Thread ID for the breakpoint.\n\
1061 1.1 christos If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
1062 1.1 christos If the value is None, then this breakpoint is not task-specific.\n\
1063 1.1 christos No other type of value can be used.", NULL },
1064 1.1 christos { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
1065 1.1 christos "Number of times this breakpoint should be automatically continued.",
1066 1.1 christos NULL },
1067 1.1 christos { "number", bppy_get_number, NULL,
1068 1.1 christos "Breakpoint's number assigned by GDB.", NULL },
1069 1.1 christos { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
1070 1.1 christos "Number of times the breakpoint has been hit.\n\
1071 1.1 christos Can be set to zero to clear the count. No other value is valid\n\
1072 1.1 christos when setting this property.", NULL },
1073 1.1 christos { "location", bppy_get_location, NULL,
1074 1.1 christos "Location of the breakpoint, as specified by the user.", NULL},
1075 1.1 christos { "expression", bppy_get_expression, NULL,
1076 1.1 christos "Expression of the breakpoint, as specified by the user.", NULL},
1077 1.1 christos { "condition", bppy_get_condition, bppy_set_condition,
1078 1.1 christos "Condition of the breakpoint, as specified by the user,\
1079 1.1 christos or None if no condition set."},
1080 1.1 christos { "commands", bppy_get_commands, NULL,
1081 1.1 christos "Commands of the breakpoint, as specified by the user."},
1082 1.1 christos { "type", bppy_get_type, NULL,
1083 1.1 christos "Type of breakpoint."},
1084 1.6 christos { "visible", bppy_get_visibility, NULL,
1085 1.6 christos "Whether the breakpoint is visible to the user."},
1086 1.1 christos { "temporary", bppy_get_temporary, NULL,
1087 1.1 christos "Whether this breakpoint is a temporary breakpoint."},
1088 1.1 christos { "pending", bppy_get_pending, NULL,
1089 1.1 christos "Whether this breakpoint is a pending breakpoint."},
1090 1.1 christos { NULL } /* Sentinel. */
1091 1.1 christos };
1092 1.1 christos
1093 1.1 christos static PyMethodDef breakpoint_object_methods[] =
1094 1.1 christos {
1095 1.1 christos { "is_valid", bppy_is_valid, METH_NOARGS,
1096 1.1 christos "Return true if this breakpoint is valid, false if not." },
1097 1.1 christos { "delete", bppy_delete_breakpoint, METH_NOARGS,
1098 1.1 christos "Delete the underlying GDB breakpoint." },
1099 1.1 christos { NULL } /* Sentinel. */
1100 1.1 christos };
1101 1.1 christos
1102 1.1 christos PyTypeObject breakpoint_object_type =
1103 1.1 christos {
1104 1.1 christos PyVarObject_HEAD_INIT (NULL, 0)
1105 1.1 christos "gdb.Breakpoint", /*tp_name*/
1106 1.1 christos sizeof (gdbpy_breakpoint_object), /*tp_basicsize*/
1107 1.1 christos 0, /*tp_itemsize*/
1108 1.1 christos 0, /*tp_dealloc*/
1109 1.1 christos 0, /*tp_print*/
1110 1.1 christos 0, /*tp_getattr*/
1111 1.1 christos 0, /*tp_setattr*/
1112 1.1 christos 0, /*tp_compare*/
1113 1.1 christos 0, /*tp_repr*/
1114 1.1 christos 0, /*tp_as_number*/
1115 1.1 christos 0, /*tp_as_sequence*/
1116 1.1 christos 0, /*tp_as_mapping*/
1117 1.1 christos 0, /*tp_hash */
1118 1.1 christos 0, /*tp_call*/
1119 1.1 christos 0, /*tp_str*/
1120 1.1 christos 0, /*tp_getattro*/
1121 1.1 christos (setattrofunc)local_setattro, /*tp_setattro */
1122 1.1 christos 0, /*tp_as_buffer*/
1123 1.1 christos Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1124 1.1 christos "GDB breakpoint object", /* tp_doc */
1125 1.1 christos 0, /* tp_traverse */
1126 1.1 christos 0, /* tp_clear */
1127 1.1 christos 0, /* tp_richcompare */
1128 1.1 christos 0, /* tp_weaklistoffset */
1129 1.1 christos 0, /* tp_iter */
1130 1.1 christos 0, /* tp_iternext */
1131 1.1 christos breakpoint_object_methods, /* tp_methods */
1132 1.1 christos 0, /* tp_members */
1133 1.1 christos breakpoint_object_getset, /* tp_getset */
1134 1.1 christos 0, /* tp_base */
1135 1.1 christos 0, /* tp_dict */
1136 1.1 christos 0, /* tp_descr_get */
1137 1.1 christos 0, /* tp_descr_set */
1138 0, /* tp_dictoffset */
1139 bppy_init, /* tp_init */
1140 0, /* tp_alloc */
1141 };
1142