2011-03-11 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
461 if (newvalue != Py_None)
462 xfree (exp);
463
464 GDB_PY_SET_HANDLE_EXCEPTION (except);
465
466 return 0;
467 }
468
469 /* Python function to get the commands attached to a breakpoint. */
470 static PyObject *
471 bppy_get_commands (PyObject *self, void *closure)
472 {
473 breakpoint_object *self_bp = (breakpoint_object *) self;
474 struct breakpoint *bp = self_bp->bp;
475 long length;
476 volatile struct gdb_exception except;
477 struct ui_file *string_file;
478 struct cleanup *chain;
479 PyObject *result;
480 char *cmdstr;
481
482 BPPY_REQUIRE_VALID (self_bp);
483
484 if (! self_bp->bp->commands)
485 Py_RETURN_NONE;
486
487 string_file = mem_fileopen ();
488 chain = make_cleanup_ui_file_delete (string_file);
489
490 ui_out_redirect (uiout, string_file);
491 TRY_CATCH (except, RETURN_MASK_ALL)
492 {
493 print_command_lines (uiout, breakpoint_commands (bp), 0);
494 }
495 ui_out_redirect (uiout, NULL);
496 GDB_PY_HANDLE_EXCEPTION (except);
497
498 cmdstr = ui_file_xstrdup (string_file, &length);
499 make_cleanup (xfree, cmdstr);
500 result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
501 do_cleanups (chain);
502 return result;
503 }
504
505 /* Python function to get the breakpoint type. */
506 static PyObject *
507 bppy_get_type (PyObject *self, void *closure)
508 {
509 breakpoint_object *self_bp = (breakpoint_object *) self;
510
511 BPPY_REQUIRE_VALID (self_bp);
512
513 return PyInt_FromLong (self_bp->bp->type);
514 }
515
516 /* Python function to get the visibility of the breakpoint. */
517
518 static PyObject *
519 bppy_get_visibility (PyObject *self, void *closure)
520 {
521 breakpoint_object *self_bp = (breakpoint_object *) self;
522
523 BPPY_REQUIRE_VALID (self_bp);
524
525 if (self_bp->bp->number < 0)
526 Py_RETURN_FALSE;
527
528 Py_RETURN_TRUE;
529 }
530
531 /* Python function to get the breakpoint's number. */
532 static PyObject *
533 bppy_get_number (PyObject *self, void *closure)
534 {
535 breakpoint_object *self_bp = (breakpoint_object *) self;
536
537 BPPY_REQUIRE_VALID (self_bp);
538
539 return PyInt_FromLong (self_bp->number);
540 }
541
542 /* Python function to get the breakpoint's thread ID. */
543 static PyObject *
544 bppy_get_thread (PyObject *self, void *closure)
545 {
546 breakpoint_object *self_bp = (breakpoint_object *) self;
547
548 BPPY_REQUIRE_VALID (self_bp);
549
550 if (self_bp->bp->thread == -1)
551 Py_RETURN_NONE;
552
553 return PyInt_FromLong (self_bp->bp->thread);
554 }
555
556 /* Python function to get the breakpoint's task ID (in Ada). */
557 static PyObject *
558 bppy_get_task (PyObject *self, void *closure)
559 {
560 breakpoint_object *self_bp = (breakpoint_object *) self;
561
562 BPPY_REQUIRE_VALID (self_bp);
563
564 if (self_bp->bp->task == 0)
565 Py_RETURN_NONE;
566
567 return PyInt_FromLong (self_bp->bp->task);
568 }
569
570 /* Python function to get the breakpoint's hit count. */
571 static PyObject *
572 bppy_get_hit_count (PyObject *self, void *closure)
573 {
574 breakpoint_object *self_bp = (breakpoint_object *) self;
575
576 BPPY_REQUIRE_VALID (self_bp);
577
578 return PyInt_FromLong (self_bp->bp->hit_count);
579 }
580
581 /* Python function to get the breakpoint's ignore count. */
582 static PyObject *
583 bppy_get_ignore_count (PyObject *self, void *closure)
584 {
585 breakpoint_object *self_bp = (breakpoint_object *) self;
586
587 BPPY_REQUIRE_VALID (self_bp);
588
589 return PyInt_FromLong (self_bp->bp->ignore_count);
590 }
591
592 /* Python function to create a new breakpoint. */
593 static PyObject *
594 bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
595 {
596 PyObject *result;
597 static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
598 char *spec;
599 int type = bp_breakpoint;
600 int access_type = hw_write;
601 PyObject *internal = NULL;
602 int internal_bp = 0;
603 volatile struct gdb_exception except;
604
605 if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
606 &spec, &type, &access_type, &internal))
607 return NULL;
608
609 if (internal)
610 {
611 internal_bp = PyObject_IsTrue (internal);
612 if (internal_bp == -1)
613 return NULL;
614 }
615
616 result = subtype->tp_alloc (subtype, 0);
617 if (! result)
618 return NULL;
619 bppy_pending_object = (breakpoint_object *) result;
620 bppy_pending_object->number = -1;
621 bppy_pending_object->bp = NULL;
622
623 TRY_CATCH (except, RETURN_MASK_ALL)
624 {
625 switch (type)
626 {
627 case bp_breakpoint:
628 {
629 create_breakpoint (python_gdbarch,
630 spec, NULL, -1,
631 0,
632 0, bp_breakpoint,
633 0,
634 AUTO_BOOLEAN_TRUE,
635 NULL, 0, 1, internal_bp);
636 break;
637 }
638 case bp_watchpoint:
639 {
640 if (access_type == hw_write)
641 watch_command_wrapper (spec, 0, internal_bp);
642 else if (access_type == hw_access)
643 awatch_command_wrapper (spec, 0, internal_bp);
644 else if (access_type == hw_read)
645 rwatch_command_wrapper (spec, 0, internal_bp);
646 else
647 error(_("Cannot understand watchpoint access type."));
648 break;
649 }
650 default:
651 error(_("Do not understand breakpoint type to set."));
652 }
653 }
654 if (except.reason < 0)
655 {
656 subtype->tp_free (result);
657 return PyErr_Format (except.reason == RETURN_QUIT
658 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
659 "%s", except.message);
660 }
661
662 BPPY_REQUIRE_VALID ((breakpoint_object *) result);
663 return result;
664 }
665
666 \f
667
668 static int
669 build_bp_list (struct breakpoint *b, void *arg)
670 {
671 PyObject *list = arg;
672 PyObject *bp = (PyObject *) b->py_bp_object;
673 int iserr = 0;
674
675 /* Not all breakpoints will have a companion Python object.
676 Only breakpoints that were created via bppy_new, or
677 breakpoints that were created externally and are tracked by
678 the Python Scripting API. */
679 if (bp)
680 iserr = PyList_Append (list, bp);
681
682 if (iserr == -1)
683 return 1;
684
685 return 0;
686 }
687
688 /* Static function to return a tuple holding all breakpoints. */
689
690 PyObject *
691 gdbpy_breakpoints (PyObject *self, PyObject *args)
692 {
693 PyObject *list;
694
695 if (bppy_live == 0)
696 Py_RETURN_NONE;
697
698 list = PyList_New (0);
699 if (!list)
700 return NULL;
701
702 /* If iteratre_over_breakpoints returns non NULL it signals an error
703 condition. In that case abandon building the list and return
704 NULL. */
705 if (iterate_over_breakpoints (build_bp_list, list) != NULL)
706 {
707 Py_DECREF (list);
708 return NULL;
709 }
710
711 return PyList_AsTuple (list);
712 }
713
714 \f
715
716 /* Event callback functions. */
717
718 /* Callback that is used when a breakpoint is created. This function
719 will create a new Python breakpoint object. */
720 static void
721 gdbpy_breakpoint_created (int num)
722 {
723 breakpoint_object *newbp;
724 struct breakpoint *bp = NULL;
725 PyGILState_STATE state;
726
727 bp = get_breakpoint (num);
728 if (! bp)
729 return;
730
731 if (num < 0 && bppy_pending_object == NULL)
732 return;
733
734 if (bp->type != bp_breakpoint
735 && bp->type != bp_watchpoint
736 && bp->type != bp_hardware_watchpoint
737 && bp->type != bp_read_watchpoint
738 && bp->type != bp_access_watchpoint)
739 return;
740
741 state = PyGILState_Ensure ();
742
743 if (bppy_pending_object)
744 {
745 newbp = bppy_pending_object;
746 bppy_pending_object = NULL;
747 }
748 else
749 newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
750 if (newbp)
751 {
752 newbp->number = num;
753 newbp->bp = bp;
754 newbp->bp->py_bp_object = newbp;
755 Py_INCREF (newbp);
756 ++bppy_live;
757 }
758 else
759 {
760 PyErr_SetString (PyExc_RuntimeError,
761 _("Error while creating breakpoint from GDB."));
762 gdbpy_print_stack ();
763 }
764
765 PyGILState_Release (state);
766 }
767
768 /* Callback that is used when a breakpoint is deleted. This will
769 invalidate the corresponding Python object. */
770 static void
771 gdbpy_breakpoint_deleted (int num)
772 {
773 PyGILState_STATE state;
774 struct breakpoint *bp = NULL;
775 breakpoint_object *bp_obj;
776
777 state = PyGILState_Ensure ();
778 bp = get_breakpoint (num);
779 if (! bp)
780 return;
781
782 bp_obj = bp->py_bp_object;
783 if (bp_obj)
784 {
785 bp_obj->bp = NULL;
786 --bppy_live;
787 Py_DECREF (bp_obj);
788 }
789 PyGILState_Release (state);
790 }
791
792 \f
793
794 /* Initialize the Python breakpoint code. */
795 void
796 gdbpy_initialize_breakpoints (void)
797 {
798 int i;
799
800 breakpoint_object_type.tp_new = bppy_new;
801 if (PyType_Ready (&breakpoint_object_type) < 0)
802 return;
803
804 Py_INCREF (&breakpoint_object_type);
805 PyModule_AddObject (gdb_module, "Breakpoint",
806 (PyObject *) &breakpoint_object_type);
807
808 observer_attach_breakpoint_created (gdbpy_breakpoint_created);
809 observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
810
811 /* Add breakpoint types constants. */
812 for (i = 0; pybp_codes[i].name; ++i)
813 {
814 if (PyModule_AddIntConstant (gdb_module,
815 /* Cast needed for Python 2.4. */
816 (char *) pybp_codes[i].name,
817 pybp_codes[i].code) < 0)
818 return;
819 }
820
821 /* Add watchpoint types constants. */
822 for (i = 0; pybp_watch_types[i].name; ++i)
823 {
824 if (PyModule_AddIntConstant (gdb_module,
825 /* Cast needed for Python 2.4. */
826 (char *) pybp_watch_types[i].name,
827 pybp_watch_types[i].code) < 0)
828 return;
829 }
830
831 }
832
833 \f
834
835 static PyGetSetDef breakpoint_object_getset[] = {
836 { "enabled", bppy_get_enabled, bppy_set_enabled,
837 "Boolean telling whether the breakpoint is enabled.", NULL },
838 { "silent", bppy_get_silent, bppy_set_silent,
839 "Boolean telling whether the breakpoint is silent.", NULL },
840 { "thread", bppy_get_thread, bppy_set_thread,
841 "Thread ID for the breakpoint.\n\
842 If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
843 If the value is None, then this breakpoint is not thread-specific.\n\
844 No other type of value can be used.", NULL },
845 { "task", bppy_get_task, bppy_set_task,
846 "Thread ID for the breakpoint.\n\
847 If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
848 If the value is None, then this breakpoint is not task-specific.\n\
849 No other type of value can be used.", NULL },
850 { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
851 "Number of times this breakpoint should be automatically continued.",
852 NULL },
853 { "number", bppy_get_number, NULL,
854 "Breakpoint's number assigned by GDB.", NULL },
855 { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
856 "Number of times the breakpoint has been hit.\n\
857 Can be set to zero to clear the count. No other value is valid\n\
858 when setting this property.", NULL },
859 { "location", bppy_get_location, NULL,
860 "Location of the breakpoint, as specified by the user.", NULL},
861 { "expression", bppy_get_expression, NULL,
862 "Expression of the breakpoint, as specified by the user.", NULL},
863 { "condition", bppy_get_condition, bppy_set_condition,
864 "Condition of the breakpoint, as specified by the user,\
865 or None if no condition set."},
866 { "commands", bppy_get_commands, NULL,
867 "Commands of the breakpoint, as specified by the user."},
868 { "type", bppy_get_type, NULL,
869 "Type of breakpoint."},
870 { "visible", bppy_get_visibility, NULL,
871 "Whether the breakpoint is visible to the user."},
872 { NULL } /* Sentinel. */
873 };
874
875 static PyMethodDef breakpoint_object_methods[] =
876 {
877 { "is_valid", bppy_is_valid, METH_NOARGS,
878 "Return true if this breakpoint is valid, false if not." },
879 { "delete", bppy_delete_breakpoint, METH_NOARGS,
880 "Delete the underlying GDB breakpoint." },
881 { NULL } /* Sentinel. */
882 };
883
884 static PyTypeObject breakpoint_object_type =
885 {
886 PyObject_HEAD_INIT (NULL)
887 0, /*ob_size*/
888 "gdb.Breakpoint", /*tp_name*/
889 sizeof (breakpoint_object), /*tp_basicsize*/
890 0, /*tp_itemsize*/
891 0, /*tp_dealloc*/
892 0, /*tp_print*/
893 0, /*tp_getattr*/
894 0, /*tp_setattr*/
895 0, /*tp_compare*/
896 0, /*tp_repr*/
897 0, /*tp_as_number*/
898 0, /*tp_as_sequence*/
899 0, /*tp_as_mapping*/
900 0, /*tp_hash */
901 0, /*tp_call*/
902 0, /*tp_str*/
903 0, /*tp_getattro*/
904 0, /*tp_setattro*/
905 0, /*tp_as_buffer*/
906 Py_TPFLAGS_DEFAULT, /*tp_flags*/
907 "GDB breakpoint object", /* tp_doc */
908 0, /* tp_traverse */
909 0, /* tp_clear */
910 0, /* tp_richcompare */
911 0, /* tp_weaklistoffset */
912 0, /* tp_iter */
913 0, /* tp_iternext */
914 breakpoint_object_methods, /* tp_methods */
915 0, /* tp_members */
916 breakpoint_object_getset /* tp_getset */
917 };
This page took 0.075718 seconds and 5 git commands to generate.