2011-02-27 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / python / py-breakpoint.c
1 /* Python interface to breakpoints
2
3 Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "value.h"
22 #include "exceptions.h"
23 #include "python-internal.h"
24 #include "charset.h"
25 #include "breakpoint.h"
26 #include "gdbcmd.h"
27 #include "gdbthread.h"
28 #include "observer.h"
29 #include "cli/cli-script.h"
30 #include "ada-lang.h"
31
32 static PyTypeObject breakpoint_object_type;
33
34 /* Number of live breakpoints. */
35 static int bppy_live;
36
37 /* Variables used to pass information between the Breakpoint
38 constructor and the breakpoint-created hook function. */
39 static breakpoint_object *bppy_pending_object;
40
41 struct breakpoint_object
42 {
43 PyObject_HEAD
44
45 /* The breakpoint number according to gdb. */
46 int number;
47
48 /* The gdb breakpoint object, or NULL if the breakpoint has been
49 deleted. */
50 struct breakpoint *bp;
51 };
52
53 /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
54 exception if it is invalid. */
55 #define BPPY_REQUIRE_VALID(Breakpoint) \
56 do { \
57 if ((Breakpoint)->bp == NULL) \
58 return PyErr_Format (PyExc_RuntimeError, \
59 _("Breakpoint %d is invalid."), \
60 (Breakpoint)->number); \
61 } while (0)
62
63 /* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
64 exception if it is invalid. This macro is for use in setter functions. */
65 #define BPPY_SET_REQUIRE_VALID(Breakpoint) \
66 do { \
67 if ((Breakpoint)->bp == NULL) \
68 { \
69 PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
70 (Breakpoint)->number); \
71 return -1; \
72 } \
73 } while (0)
74
75 /* This is used to initialize various gdb.bp_* constants. */
76 struct pybp_code
77 {
78 /* The name. */
79 const char *name;
80 /* The code. */
81 enum type_code code;
82 };
83
84 /* Entries related to the type of user set breakpoints. */
85 static struct pybp_code pybp_codes[] =
86 {
87 { "BP_NONE", bp_none},
88 { "BP_BREAKPOINT", bp_breakpoint},
89 { "BP_WATCHPOINT", bp_watchpoint},
90 { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
91 { "BP_READ_WATCHPOINT", bp_read_watchpoint},
92 { "BP_ACCESS_WATCHPOINT", bp_access_watchpoint},
93 {NULL} /* Sentinel. */
94 };
95
96 /* Entries related to the type of watchpoint. */
97 static struct pybp_code pybp_watch_types[] =
98 {
99 { "WP_READ", hw_read},
100 { "WP_WRITE", hw_write},
101 { "WP_ACCESS", hw_access},
102 {NULL} /* Sentinel. */
103 };
104
105 /* Python function which checks the validity of a breakpoint object. */
106 static PyObject *
107 bppy_is_valid (PyObject *self, PyObject *args)
108 {
109 breakpoint_object *self_bp = (breakpoint_object *) self;
110
111 if (self_bp->bp)
112 Py_RETURN_TRUE;
113 Py_RETURN_FALSE;
114 }
115
116 /* Python function to test whether or not the breakpoint is enabled. */
117 static PyObject *
118 bppy_get_enabled (PyObject *self, void *closure)
119 {
120 breakpoint_object *self_bp = (breakpoint_object *) self;
121
122 BPPY_REQUIRE_VALID (self_bp);
123 if (! self_bp->bp)
124 Py_RETURN_FALSE;
125 if (self_bp->bp->enable_state == bp_enabled)
126 Py_RETURN_TRUE;
127 Py_RETURN_FALSE;
128 }
129
130 /* Python function to test whether or not the breakpoint is silent. */
131 static PyObject *
132 bppy_get_silent (PyObject *self, void *closure)
133 {
134 breakpoint_object *self_bp = (breakpoint_object *) self;
135
136 BPPY_REQUIRE_VALID (self_bp);
137 if (self_bp->bp->silent)
138 Py_RETURN_TRUE;
139 Py_RETURN_FALSE;
140 }
141
142 /* Python function to set the enabled state of a breakpoint. */
143 static int
144 bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
145 {
146 breakpoint_object *self_bp = (breakpoint_object *) self;
147 int cmp;
148
149 BPPY_SET_REQUIRE_VALID (self_bp);
150
151 if (newvalue == NULL)
152 {
153 PyErr_SetString (PyExc_TypeError,
154 _("Cannot delete `enabled' attribute."));
155
156 return -1;
157 }
158 else if (! PyBool_Check (newvalue))
159 {
160 PyErr_SetString (PyExc_TypeError,
161 _("The value of `enabled' must be a boolean."));
162 return -1;
163 }
164
165 cmp = PyObject_IsTrue (newvalue);
166 if (cmp < 0)
167 return -1;
168 else if (cmp == 1)
169 enable_breakpoint (self_bp->bp);
170 else
171 disable_breakpoint (self_bp->bp);
172 return 0;
173 }
174
175 /* Python function to set the 'silent' state of a breakpoint. */
176 static int
177 bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
178 {
179 breakpoint_object *self_bp = (breakpoint_object *) self;
180 int cmp;
181
182 BPPY_SET_REQUIRE_VALID (self_bp);
183
184 if (newvalue == NULL)
185 {
186 PyErr_SetString (PyExc_TypeError,
187 _("Cannot delete `silent' attribute."));
188 return -1;
189 }
190 else if (! PyBool_Check (newvalue))
191 {
192 PyErr_SetString (PyExc_TypeError,
193 _("The value of `silent' must be a boolean."));
194 return -1;
195 }
196
197 cmp = PyObject_IsTrue (newvalue);
198 if (cmp < 0)
199 return -1;
200 else
201 breakpoint_set_silent (self_bp->bp, cmp);
202
203 return 0;
204 }
205
206 /* Python function to set the thread of a breakpoint. */
207 static int
208 bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
209 {
210 breakpoint_object *self_bp = (breakpoint_object *) self;
211 long id;
212
213 BPPY_SET_REQUIRE_VALID (self_bp);
214
215 if (newvalue == NULL)
216 {
217 PyErr_SetString (PyExc_TypeError,
218 _("Cannot delete `thread' attribute."));
219 return -1;
220 }
221 else if (PyInt_Check (newvalue))
222 {
223 if (! gdb_py_int_as_long (newvalue, &id))
224 return -1;
225
226 if (! valid_thread_id (id))
227 {
228 PyErr_SetString (PyExc_RuntimeError,
229 _("Invalid thread ID."));
230 return -1;
231 }
232 }
233 else if (newvalue == Py_None)
234 id = -1;
235 else
236 {
237 PyErr_SetString (PyExc_TypeError,
238 _("The value of `thread' must be an integer or None."));
239 return -1;
240 }
241
242 breakpoint_set_thread (self_bp->bp, id);
243
244 return 0;
245 }
246
247 /* Python function to set the (Ada) task of a breakpoint. */
248 static int
249 bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
250 {
251 breakpoint_object *self_bp = (breakpoint_object *) self;
252 long id;
253
254 BPPY_SET_REQUIRE_VALID (self_bp);
255
256 if (newvalue == NULL)
257 {
258 PyErr_SetString (PyExc_TypeError,
259 _("Cannot delete `task' attribute."));
260 return -1;
261 }
262 else if (PyInt_Check (newvalue))
263 {
264 if (! gdb_py_int_as_long (newvalue, &id))
265 return -1;
266
267 if (! valid_task_id (id))
268 {
269 PyErr_SetString (PyExc_RuntimeError,
270 _("Invalid task ID."));
271 return -1;
272 }
273 }
274 else if (newvalue == Py_None)
275 id = 0;
276 else
277 {
278 PyErr_SetString (PyExc_TypeError,
279 _("The value of `task' must be an integer or None."));
280 return -1;
281 }
282
283 breakpoint_set_task (self_bp->bp, id);
284
285 return 0;
286 }
287
288 /* Python function which deletes the underlying GDB breakpoint. This
289 triggers the breakpoint_deleted observer which will call
290 gdbpy_breakpoint_deleted; that function cleans up the Python
291 sections. */
292
293 static PyObject *
294 bppy_delete_breakpoint (PyObject *self, PyObject *args)
295 {
296 breakpoint_object *self_bp = (breakpoint_object *) self;
297
298 BPPY_REQUIRE_VALID (self_bp);
299
300 delete_breakpoint (self_bp->bp);
301
302 Py_RETURN_NONE;
303 }
304
305
306 /* Python function to set the ignore count of a breakpoint. */
307 static int
308 bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
309 {
310 breakpoint_object *self_bp = (breakpoint_object *) self;
311 long value;
312
313 BPPY_SET_REQUIRE_VALID (self_bp);
314
315 if (newvalue == NULL)
316 {
317 PyErr_SetString (PyExc_TypeError,
318 _("Cannot delete `ignore_count' attribute."));
319 return -1;
320 }
321 else if (! PyInt_Check (newvalue))
322 {
323 PyErr_SetString (PyExc_TypeError,
324 _("The value of `ignore_count' must be an integer."));
325 return -1;
326 }
327
328 if (! gdb_py_int_as_long (newvalue, &value))
329 return -1;
330
331 if (value < 0)
332 value = 0;
333 set_ignore_count (self_bp->number, (int) value, 0);
334
335 return 0;
336 }
337
338 /* Python function to set the hit count of a breakpoint. */
339 static int
340 bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
341 {
342 breakpoint_object *self_bp = (breakpoint_object *) self;
343
344 BPPY_SET_REQUIRE_VALID (self_bp);
345
346 if (newvalue == NULL)
347 {
348 PyErr_SetString (PyExc_TypeError,
349 _("Cannot delete `hit_count' attribute."));
350 return -1;
351 }
352 else
353 {
354 long value;
355
356 if (! gdb_py_int_as_long (newvalue, &value))
357 return -1;
358
359 if (value != 0)
360 {
361 PyErr_SetString (PyExc_AttributeError,
362 _("The value of `hit_count' must be zero."));
363 return -1;
364 }
365 }
366
367 self_bp->bp->hit_count = 0;
368
369 return 0;
370 }
371
372 /* Python function to get the location of a breakpoint. */
373 static PyObject *
374 bppy_get_location (PyObject *self, void *closure)
375 {
376 char *str;
377 breakpoint_object *obj = (breakpoint_object *) self;
378
379 BPPY_REQUIRE_VALID (obj);
380
381 if (obj->bp->type != bp_breakpoint)
382 Py_RETURN_NONE;
383
384 str = obj->bp->addr_string;
385
386 if (! str)
387 str = "";
388 return PyString_Decode (str, strlen (str), host_charset (), NULL);
389 }
390
391 /* Python function to get the breakpoint expression. */
392 static PyObject *
393 bppy_get_expression (PyObject *self, void *closure)
394 {
395 char *str;
396 breakpoint_object *obj = (breakpoint_object *) self;
397
398 BPPY_REQUIRE_VALID (obj);
399
400 if (obj->bp->type != bp_watchpoint
401 && obj->bp->type != bp_hardware_watchpoint
402 && obj->bp->type != bp_read_watchpoint
403 && obj->bp->type != bp_access_watchpoint)
404 Py_RETURN_NONE;
405
406 str = obj->bp->exp_string;
407 if (! str)
408 str = "";
409
410 return PyString_Decode (str, strlen (str), host_charset (), NULL);
411 }
412
413 /* Python function to get the condition expression of a breakpoint. */
414 static PyObject *
415 bppy_get_condition (PyObject *self, void *closure)
416 {
417 char *str;
418 breakpoint_object *obj = (breakpoint_object *) self;
419
420 BPPY_REQUIRE_VALID (obj);
421
422 str = obj->bp->cond_string;
423 if (! str)
424 Py_RETURN_NONE;
425
426 return PyString_Decode (str, strlen (str), host_charset (), NULL);
427 }
428
429 /* Returns 0 on success. Returns -1 on error, with a python exception set.
430 */
431
432 static int
433 bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
434 {
435 char *exp;
436 breakpoint_object *self_bp = (breakpoint_object *) self;
437 volatile struct gdb_exception except;
438
439 BPPY_SET_REQUIRE_VALID (self_bp);
440
441 if (newvalue == NULL)
442 {
443 PyErr_SetString (PyExc_TypeError,
444 _("Cannot delete `condition' attribute."));
445 return -1;
446 }
447 else if (newvalue == Py_None)
448 exp = "";
449 else
450 {
451 exp = python_string_to_host_string (newvalue);
452 if (exp == NULL)
453 return -1;
454 }
455
456 TRY_CATCH (except, RETURN_MASK_ALL)
457 {
458 set_breakpoint_condition (self_bp->bp, exp, 0);
459 }
460 GDB_PY_SET_HANDLE_EXCEPTION (except);
461
462 return 0;
463 }
464
465 /* Python function to get the commands attached to a breakpoint. */
466 static PyObject *
467 bppy_get_commands (PyObject *self, void *closure)
468 {
469 breakpoint_object *self_bp = (breakpoint_object *) self;
470 struct breakpoint *bp = self_bp->bp;
471 long length;
472 volatile struct gdb_exception except;
473 struct ui_file *string_file;
474 struct cleanup *chain;
475 PyObject *result;
476 char *cmdstr;
477
478 BPPY_REQUIRE_VALID (self_bp);
479
480 if (! self_bp->bp->commands)
481 Py_RETURN_NONE;
482
483 string_file = mem_fileopen ();
484 chain = make_cleanup_ui_file_delete (string_file);
485
486 ui_out_redirect (uiout, string_file);
487 TRY_CATCH (except, RETURN_MASK_ALL)
488 {
489 print_command_lines (uiout, breakpoint_commands (bp), 0);
490 }
491 ui_out_redirect (uiout, NULL);
492 GDB_PY_HANDLE_EXCEPTION (except);
493
494 cmdstr = ui_file_xstrdup (string_file, &length);
495 make_cleanup (xfree, cmdstr);
496 result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
497 do_cleanups (chain);
498 return result;
499 }
500
501 /* Python function to get the breakpoint type. */
502 static PyObject *
503 bppy_get_type (PyObject *self, void *closure)
504 {
505 breakpoint_object *self_bp = (breakpoint_object *) self;
506
507 BPPY_REQUIRE_VALID (self_bp);
508
509 return PyInt_FromLong (self_bp->bp->type);
510 }
511
512 /* Python function to get the visibility of the breakpoint. */
513
514 static PyObject *
515 bppy_get_visibility (PyObject *self, void *closure)
516 {
517 breakpoint_object *self_bp = (breakpoint_object *) self;
518
519 BPPY_REQUIRE_VALID (self_bp);
520
521 if (self_bp->bp->number < 0)
522 Py_RETURN_FALSE;
523
524 Py_RETURN_TRUE;
525 }
526
527 /* Python function to get the breakpoint's number. */
528 static PyObject *
529 bppy_get_number (PyObject *self, void *closure)
530 {
531 breakpoint_object *self_bp = (breakpoint_object *) self;
532
533 BPPY_REQUIRE_VALID (self_bp);
534
535 return PyInt_FromLong (self_bp->number);
536 }
537
538 /* Python function to get the breakpoint's thread ID. */
539 static PyObject *
540 bppy_get_thread (PyObject *self, void *closure)
541 {
542 breakpoint_object *self_bp = (breakpoint_object *) self;
543
544 BPPY_REQUIRE_VALID (self_bp);
545
546 if (self_bp->bp->thread == -1)
547 Py_RETURN_NONE;
548
549 return PyInt_FromLong (self_bp->bp->thread);
550 }
551
552 /* Python function to get the breakpoint's task ID (in Ada). */
553 static PyObject *
554 bppy_get_task (PyObject *self, void *closure)
555 {
556 breakpoint_object *self_bp = (breakpoint_object *) self;
557
558 BPPY_REQUIRE_VALID (self_bp);
559
560 if (self_bp->bp->task == 0)
561 Py_RETURN_NONE;
562
563 return PyInt_FromLong (self_bp->bp->task);
564 }
565
566 /* Python function to get the breakpoint's hit count. */
567 static PyObject *
568 bppy_get_hit_count (PyObject *self, void *closure)
569 {
570 breakpoint_object *self_bp = (breakpoint_object *) self;
571
572 BPPY_REQUIRE_VALID (self_bp);
573
574 return PyInt_FromLong (self_bp->bp->hit_count);
575 }
576
577 /* Python function to get the breakpoint's ignore count. */
578 static PyObject *
579 bppy_get_ignore_count (PyObject *self, void *closure)
580 {
581 breakpoint_object *self_bp = (breakpoint_object *) self;
582
583 BPPY_REQUIRE_VALID (self_bp);
584
585 return PyInt_FromLong (self_bp->bp->ignore_count);
586 }
587
588 /* Python function to create a new breakpoint. */
589 static PyObject *
590 bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
591 {
592 PyObject *result;
593 static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
594 char *spec;
595 int type = bp_breakpoint;
596 int access_type = hw_write;
597 PyObject *internal = NULL;
598 int internal_bp = 0;
599 volatile struct gdb_exception except;
600
601 if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
602 &spec, &type, &access_type, &internal))
603 return NULL;
604
605 if (internal)
606 {
607 internal_bp = PyObject_IsTrue (internal);
608 if (internal_bp == -1)
609 return NULL;
610 }
611
612 result = subtype->tp_alloc (subtype, 0);
613 if (! result)
614 return NULL;
615 bppy_pending_object = (breakpoint_object *) result;
616 bppy_pending_object->number = -1;
617 bppy_pending_object->bp = NULL;
618
619 TRY_CATCH (except, RETURN_MASK_ALL)
620 {
621 switch (type)
622 {
623 case bp_breakpoint:
624 {
625 create_breakpoint (python_gdbarch,
626 spec, NULL, -1,
627 0,
628 0, bp_breakpoint,
629 0,
630 AUTO_BOOLEAN_TRUE,
631 NULL, 0, 1, internal_bp);
632 break;
633 }
634 case bp_watchpoint:
635 {
636 if (access_type == hw_write)
637 watch_command_wrapper (spec, 0, internal_bp);
638 else if (access_type == hw_access)
639 awatch_command_wrapper (spec, 0, internal_bp);
640 else if (access_type == hw_read)
641 rwatch_command_wrapper (spec, 0, internal_bp);
642 else
643 error(_("Cannot understand watchpoint access type."));
644 break;
645 }
646 default:
647 error(_("Do not understand breakpoint type to set."));
648 }
649 }
650 if (except.reason < 0)
651 {
652 subtype->tp_free (result);
653 return PyErr_Format (except.reason == RETURN_QUIT
654 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
655 "%s", except.message);
656 }
657
658 BPPY_REQUIRE_VALID ((breakpoint_object *) result);
659 return result;
660 }
661
662 \f
663
664 static int
665 build_bp_list (struct breakpoint *b, void *arg)
666 {
667 PyObject *list = arg;
668 PyObject *bp = (PyObject *) b->py_bp_object;
669 int iserr = 0;
670
671 /* Not all breakpoints will have a companion Python object.
672 Only breakpoints that were created via bppy_new, or
673 breakpoints that were created externally and are tracked by
674 the Python Scripting API. */
675 if (bp)
676 iserr = PyList_Append (list, bp);
677
678 if (iserr == -1)
679 return 1;
680
681 return 0;
682 }
683
684 /* Static function to return a tuple holding all breakpoints. */
685
686 PyObject *
687 gdbpy_breakpoints (PyObject *self, PyObject *args)
688 {
689 PyObject *list;
690
691 if (bppy_live == 0)
692 Py_RETURN_NONE;
693
694 list = PyList_New (0);
695 if (!list)
696 return NULL;
697
698 /* If iteratre_over_breakpoints returns non NULL it signals an error
699 condition. In that case abandon building the list and return
700 NULL. */
701 if (iterate_over_breakpoints (build_bp_list, list) != NULL)
702 {
703 Py_DECREF (list);
704 return NULL;
705 }
706
707 return PyList_AsTuple (list);
708 }
709
710 \f
711
712 /* Event callback functions. */
713
714 /* Callback that is used when a breakpoint is created. This function
715 will create a new Python breakpoint object. */
716 static void
717 gdbpy_breakpoint_created (int num)
718 {
719 breakpoint_object *newbp;
720 struct breakpoint *bp = NULL;
721 PyGILState_STATE state;
722
723 bp = get_breakpoint (num);
724 if (! bp)
725 return;
726
727 if (num < 0 && bppy_pending_object == NULL)
728 return;
729
730 if (bp->type != bp_breakpoint
731 && bp->type != bp_watchpoint
732 && bp->type != bp_hardware_watchpoint
733 && bp->type != bp_read_watchpoint
734 && bp->type != bp_access_watchpoint)
735 return;
736
737 state = PyGILState_Ensure ();
738
739 if (bppy_pending_object)
740 {
741 newbp = bppy_pending_object;
742 bppy_pending_object = NULL;
743 }
744 else
745 newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
746 if (newbp)
747 {
748 newbp->number = num;
749 newbp->bp = bp;
750 newbp->bp->py_bp_object = newbp;
751 Py_INCREF (newbp);
752 ++bppy_live;
753 }
754 else
755 {
756 PyErr_SetString (PyExc_RuntimeError,
757 _("Error while creating breakpoint from GDB."));
758 gdbpy_print_stack ();
759 }
760
761 PyGILState_Release (state);
762 }
763
764 /* Callback that is used when a breakpoint is deleted. This will
765 invalidate the corresponding Python object. */
766 static void
767 gdbpy_breakpoint_deleted (int num)
768 {
769 PyGILState_STATE state;
770 struct breakpoint *bp = NULL;
771 breakpoint_object *bp_obj;
772
773 state = PyGILState_Ensure ();
774 bp = get_breakpoint (num);
775 if (! bp)
776 return;
777
778 bp_obj = bp->py_bp_object;
779 if (bp_obj)
780 {
781 bp_obj->bp = NULL;
782 --bppy_live;
783 Py_DECREF (bp_obj);
784 }
785 PyGILState_Release (state);
786 }
787
788 \f
789
790 /* Initialize the Python breakpoint code. */
791 void
792 gdbpy_initialize_breakpoints (void)
793 {
794 int i;
795
796 breakpoint_object_type.tp_new = bppy_new;
797 if (PyType_Ready (&breakpoint_object_type) < 0)
798 return;
799
800 Py_INCREF (&breakpoint_object_type);
801 PyModule_AddObject (gdb_module, "Breakpoint",
802 (PyObject *) &breakpoint_object_type);
803
804 observer_attach_breakpoint_created (gdbpy_breakpoint_created);
805 observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
806
807 /* Add breakpoint types constants. */
808 for (i = 0; pybp_codes[i].name; ++i)
809 {
810 if (PyModule_AddIntConstant (gdb_module,
811 /* Cast needed for Python 2.4. */
812 (char *) pybp_codes[i].name,
813 pybp_codes[i].code) < 0)
814 return;
815 }
816
817 /* Add watchpoint types constants. */
818 for (i = 0; pybp_watch_types[i].name; ++i)
819 {
820 if (PyModule_AddIntConstant (gdb_module,
821 /* Cast needed for Python 2.4. */
822 (char *) pybp_watch_types[i].name,
823 pybp_watch_types[i].code) < 0)
824 return;
825 }
826
827 }
828
829 \f
830
831 static PyGetSetDef breakpoint_object_getset[] = {
832 { "enabled", bppy_get_enabled, bppy_set_enabled,
833 "Boolean telling whether the breakpoint is enabled.", NULL },
834 { "silent", bppy_get_silent, bppy_set_silent,
835 "Boolean telling whether the breakpoint is silent.", NULL },
836 { "thread", bppy_get_thread, bppy_set_thread,
837 "Thread ID for the breakpoint.\n\
838 If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
839 If the value is None, then this breakpoint is not thread-specific.\n\
840 No other type of value can be used.", NULL },
841 { "task", bppy_get_task, bppy_set_task,
842 "Thread ID for the breakpoint.\n\
843 If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
844 If the value is None, then this breakpoint is not task-specific.\n\
845 No other type of value can be used.", NULL },
846 { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
847 "Number of times this breakpoint should be automatically continued.",
848 NULL },
849 { "number", bppy_get_number, NULL,
850 "Breakpoint's number assigned by GDB.", NULL },
851 { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
852 "Number of times the breakpoint has been hit.\n\
853 Can be set to zero to clear the count. No other value is valid\n\
854 when setting this property.", NULL },
855 { "location", bppy_get_location, NULL,
856 "Location of the breakpoint, as specified by the user.", NULL},
857 { "expression", bppy_get_expression, NULL,
858 "Expression of the breakpoint, as specified by the user.", NULL},
859 { "condition", bppy_get_condition, bppy_set_condition,
860 "Condition of the breakpoint, as specified by the user,\
861 or None if no condition set."},
862 { "commands", bppy_get_commands, NULL,
863 "Commands of the breakpoint, as specified by the user."},
864 { "type", bppy_get_type, NULL,
865 "Type of breakpoint."},
866 { "visible", bppy_get_visibility, NULL,
867 "Whether the breakpoint is visible to the user."},
868 { NULL } /* Sentinel. */
869 };
870
871 static PyMethodDef breakpoint_object_methods[] =
872 {
873 { "is_valid", bppy_is_valid, METH_NOARGS,
874 "Return true if this breakpoint is valid, false if not." },
875 { "delete", bppy_delete_breakpoint, METH_NOARGS,
876 "Delete the underlying GDB breakpoint." },
877 { NULL } /* Sentinel. */
878 };
879
880 static PyTypeObject breakpoint_object_type =
881 {
882 PyObject_HEAD_INIT (NULL)
883 0, /*ob_size*/
884 "gdb.Breakpoint", /*tp_name*/
885 sizeof (breakpoint_object), /*tp_basicsize*/
886 0, /*tp_itemsize*/
887 0, /*tp_dealloc*/
888 0, /*tp_print*/
889 0, /*tp_getattr*/
890 0, /*tp_setattr*/
891 0, /*tp_compare*/
892 0, /*tp_repr*/
893 0, /*tp_as_number*/
894 0, /*tp_as_sequence*/
895 0, /*tp_as_mapping*/
896 0, /*tp_hash */
897 0, /*tp_call*/
898 0, /*tp_str*/
899 0, /*tp_getattro*/
900 0, /*tp_setattro*/
901 0, /*tp_as_buffer*/
902 Py_TPFLAGS_DEFAULT, /*tp_flags*/
903 "GDB breakpoint object", /* tp_doc */
904 0, /* tp_traverse */
905 0, /* tp_clear */
906 0, /* tp_richcompare */
907 0, /* tp_weaklistoffset */
908 0, /* tp_iter */
909 0, /* tp_iternext */
910 breakpoint_object_methods, /* tp_methods */
911 0, /* tp_members */
912 breakpoint_object_getset /* tp_getset */
913 };
This page took 0.0498 seconds and 5 git commands to generate.